Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
babaworks
Posts: 6
Registered: ‎10-23-2012
My Device: BB Dev Alpha

Strange! There is no numeric-only input for TextFieldInputMode?

TextFieldInputMode supports the following numeric input modes but none of them restrict input to just numbers.

PhoneNumber
NumbersAndPunctuation
NumericPassword
Pin

This has got to be an extremely common use-case.  Is there a work around besides filtering input as it's typed?

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Strange! There is no numeric-only input for TextFieldInputMode?

Not that I don't also miss that option, but note that some might also say they'd like "numbers and decimal place only" or "numbers and plus or minus", and so on.

Also, there's probably ways of using copy/paste to bypass the keyboard restrictions.

I short, I think filtering is probably what's required in any event... The custom keyboards are just a convenience for the user, but perhaps not a mechanism developers should rely on to restrict the input.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Contributor
babaworks
Posts: 6
Registered: ‎10-23-2012
My Device: BB Dev Alpha

Re: Strange! There is no numeric-only input for TextFieldInputMode?

That could easily be fixed by designing the options to be OR'able together like so:

TextFieldInputMode.Numeric | TextFieldInputMode.Punctionation
TextFieldInputMode.Numeric | TextFieldInputMode.Plus | TextFieldInputMode.Minus
TextFieldInputMode.Numeric | TextFieldInputMode.Decimal
TextFieldInputMode.Numeric | TextFieldInputMode.Password

Visitor
denisdagenaisOrleans
Posts: 1
Registered: ‎02-22-2013
My Device: Z10

Re: Strange! There is no numeric-only input for TextFieldInputMode?

I hve also tried the nummericandpunctuation and on the latest Z10 release using 1673 (10.0.9.), my app still accepts the full keyboard.

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Strange! There is no numeric-only input for TextFieldInputMode?

This is true... the NumbersAndPunctuation keyboard doesn't prevent text entry, it just starts off on the numeric version of that as a convenience to the user. Text filtering in some fashion is still required, or a custom data entry keyboard, at least for now.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook

Re: Strange! There is no numeric-only input for TextFieldInputMode?

I did that using RegExp

 

Here is a JS function:

    function numericOnly (textin) { // allow users to use numbers only
                 
         var m_strOut = new String (textin);
         m_strOut = m_strOut.replace(/[^\d.]/g,'');
         
         return m_strOut;
                             
    } // end numericOnly

 and call once TextChanging signal is emitted:

 

			                onTextChanging: {
			                    text = numericOnly(text)

			                }

 That should work. 

 

 

 

 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com