1. #1
    Sencha User
    Join Date
    Jul 2009
    Location
    Dallas, TX
    Posts
    5
    Vote Rating
    0
    bkgrover is on a distinguished road

      0  

    Default Unanswered: Leading zeros in numberfield (Ext.form.field.Number) in 4.x

    Unanswered: Leading zeros in numberfield (Ext.form.field.Number) in 4.x


    I'm trying to extend the numberfield to have leading zeros and wanted to see if anybody has done this before.
    I would like to have a hour, minute, and seconds fields that allow the user to enter a single number and the form field format the entry with leading zero. (i.e. The user enters 5 and tabs to the next field then the UI would show 05)

    I've search the forum and found some related post but none for the extjs 4.x.

    Here are some previous posts...
    http://www.sencha.com/forum/showthread.php?37139-Ext.ux.NumberFieldLeadingZeroes

    http://www.sencha.com/forum/showthread.php?22233-Prevent-stripping-of-Leading-Zero-s-in-NumberField



  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,684
    Answers
    130
    Vote Rating
    112
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      1  

    Default


    both approaches should also work for ext 4. in case you want to migrate my ux to ext 4, you will need to take a look at the new setValue method and adjust changes (should be quite easy).

    using a textfield with the maskRe - config set to
    Code:
    maskRe:/\d/
    is also ok. you can set a listener on the blur event and change the value of the field.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,605
    Answers
    543
    Vote Rating
    326
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Maybe this would help?

    http://www.sencha.com/forum/showthre...828#post644523

    It was intended to be used for currencies but you should be able to tweak the format to whatever you want.

  4. #4
    Sencha Premium Member fl.borovsky's Avatar
    Join Date
    Jul 2013
    Posts
    68
    Answers
    4
    Vote Rating
    4
    fl.borovsky is on a distinguished road

      0  

    Default


    add to number field config:
    Code:
    valueToRaw: function (value)
    {
        return (value < 10 ? '0' : '') + value; // any string conversion
    }

  5. #5
    Sencha User
    Join Date
    Sep 2012
    Posts
    83
    Vote Rating
    5
    mpost is on a distinguished road

      0  

    Default


    That solution doesn't handle the general case of an arbitrary length number field that needs to preserve leading zeroes. Another way to think of this problem is you want to preserve the number of significant digits to the left of the decimal.