[CLOSED] NumberField: decimal precision

  1. #1

    [CLOSED] NumberField: decimal precision

    Hello,

    When I define a numberField control with decimalPrecision set to 3, is it possible to block the user to type more than 3 digits after the decimal separator?

    Any idea?

    Romuald.
    Last edited by Daniil; Aug 17, 2010 at 11:16 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Maybe need to handle a key event which could contain custom logic.

    Example

    <ext:NumberField ID="NumberField1" runat="server" DecimalPrecision="3" EnableKeyEvents="true">
        <Listeners>
            <KeyPress Handler="your logic here...." />
        </Listeners>
    </ext:NumberField>
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Hello,

    Thank you for your reply. But could you help me find the code for the logic?

    Romuald.
  4. #4
    Hello!

    I tried to use KeyUp...It was found more difficult to implement than I thought at the beginning.
    I would suggest you to use the powerful of regular expression and handling the invalid event.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            var invalidHandler = function(field) {
                var value = field.el.getValue();
                field.el.setValue(field.fixPrecision(value));
                field.clearInvalid();
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:NumberField 
                runat="server" 
                DecimalPrecision="3" 
                DecimalSeparator="."
                Regex="^[0-9]+.?(\d{1,2})?\d?$">
            <Listeners>
                <Invalid Fn="invalidHandler"/>
            </Listeners>
        </ext:NumberField>
        </form>
    </body>
    </html>
    It doesn't block at all typing digits more than 3 after the decimal separator, but I hope it will be useful for you.
    Last edited by Daniil; Aug 13, 2010 at 11:47 PM.
  5. #5
    Hello again!

    To implement this using KeyUp event is not more difficult as I mentioned earlier.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
      
        <script type="text/javascript">
            var keyUpHandler = function(field, e) {
                var value = field.el.getValue();
                if (value[value.length - 1] != field.decimalSeparator)
                    field.el.setValue(field.fixPrecision(value));   
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:NumberField 
            runat="server" 
            DecimalPrecision="3" 
            DecimalSeparator="." 
            EnableKeyEvents="true">
            <Listeners>
                <KeyUp Fn="keyUpHandler" />
            </Listeners>
        </ext:NumberField>
        </form>
    </body>
    </html>
    Last edited by Daniil; Aug 26, 2010 at 8:11 AM.

Similar Threads

  1. numberfield control and decimal separator
    By cperriot in forum 1.x Help
    Replies: 0
    Last Post: Jul 17, 2012, 2:36 PM
  2. Replies: 2
    Last Post: Mar 17, 2011, 1:43 PM
  3. [CLOSED] Number FIeld Decimal Precision
    By CMA in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 13, 2011, 1:03 PM
  4. [CLOSED] [1.0] NumberField decimal separator issue
    By chrisbranson in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 10, 2010, 3:05 PM
  5. Decimal in NumberField
    By olimpia in forum 1.x Help
    Replies: 2
    Last Post: Aug 21, 2009, 10:18 AM

Posting Permissions