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
Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
Accepted Solution

Preventing non numeric key presses in a TextField

Hi

 

I am working on a BB10 app using Cascades. On one of my text fields I need to prevent all non numeric key presses allowing 0 - 9 and a decimal point. i have set the inputmode to phone and punctuation but obviously that still allows for other keys. The only way I can think of doing this is by checking the text 'onTextChanging' and remove any non numeric character.

 

Is there a better way?

Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: Preventing non numeric key presses in a TextField

So NumbersAndPunctuation doesnt work? Or are you using Phone and something else.

Like all of my posts
Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha

Re: Preventing non numeric key presses in a TextField

Numbers and Punctuation works but you can still type other characters such as # plus you can navigate back to the alpha keyboard.  I need to trap key presses and prevent non numeric keys.

Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha

Re: Preventing non numeric key presses in a TextField

Developer
georg22
Posts: 247
Registered: ‎11-22-2011
My Device: Blackberry Playbook

Re: Preventing non numeric key presses in a TextField

Facing the same problem and no idea too.

 

I need input for floating point numbers(digits, dot, comma).

 

In AIR SDK it was possible to assign a string to a TextField witch contains the restricted / nonrestricted keys.

 

Nothing similar here. I tried "onTextChanged" to evaluate the text after input by a Regular Expression and changing it if necessary. Unfortunally changing the text triggers the signal too - so an endless loop is created.

 

 

Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha

Re: Preventing non numeric key presses in a TextField

I have searched and searched for an answer to this but am getting no where. The only solution I have come up with is to scan what has been entered after the event and then remove any invalid characters. This looks and feels very unprofessional though.

 

I was hoping there would be a KeyPress signal or something related to the keyboard but as yet I havent found one.

 

Hoping BlackBerry will chime in here :smileyhappy:

Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: Preventing non numeric key presses in a TextField

the Roadmap says that Keyboard Support will be coming with C6 in December

Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha

Re: Preventing non numeric key presses in a TextField

Hi SlashKyle

 

Sorry for the delay, I have been on holiday.

 

The roadmap states:

 

"SDK updates to support the new 720x720 screen resolution and physical keyboard integration. UI controls are updated and resized to perfectly fit the square 720x720 screen, and will support keyboard shortcuts for efficient interaction and navigation."

 

So this is really just support for the new physical keyboard. Maybe they will include additional functionality but I was hoping someone would have come across this.

 

Still open to suggestions :smileyhappy:

 

Developer
lcaro
Posts: 95
Registered: ‎10-19-2010
My Device: Blackberry 8110

Re: Preventing non numeric key presses in a TextField

Hi theappspod,

 

Could you please let me know how did you manage to get that "unprofessional" way to remove the text that you don't want from the TextField? I think I could use it as a workaround till RIM comes up with a "professional" way to do it.

 

Thanks so much

Regards

Developer
theappspod
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha

Re: Preventing non numeric key presses in a TextField

Hi ICaro

 

unfortunately the problem persists. I have not found away round this yet. I am hoping that RIM will address the issue this month though - fingers crossed.