Search code examples
sencha-touch-2

sencha touch 2 numberfield separator


I have an ST2 app that has a numberfield for the phone number:

            {
                    xtype: 'numberfield',
                    id: 'Phone',
                    name: 'Phone',
                    cls: "detailText",
                    label: 'Phone:'
            }

I have this running on both Android and iPhone. If I enter a phone number of "555123987", the Android will display "555123987" while the iPhone will display "555,123,987".

How do I remove the commas?

I'm using a numberfield because elsewhere in the app the user uses the contents of the field to make a call. Is there another way to stop junk characters getting in there without watching keydown or something? Maybe using textfield with a regex somehow?


Solution

  • You can set the ui config to text (ui: 'text'). Like so:

    xtype: 'numberfield',
    ui: 'text',
    label: 'Phone',
    name: 'phone'
    

    That's a quick way to prevent the commas from automatically getting in there on iPhone. But it doesn't prevent the user from typing in their own "junk" characters.