Results 1 to 5 of 5

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

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Location
    Dallas, TX
    Posts
    5
    Vote Rating
    0
      0  

    Default 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,747
    Answers
    130
    Vote Rating
    129
      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

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    390
      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
    89
    Answers
    6
    Vote Rating
    11
      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
    6
      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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •