11-12-2012 11:11 AM
Ok, thanks for quick reply.
Hopefully RIM will address it. Fingers crossed ![]()
Regards
12-02-2012 01:30 PM
Can anyone help with this pleasetethering only way I could see this working was to remove all non numeric characters in ontextchanging but this didn't work. Is there anyway that I can detect what key has been pressed and cancel it if needed? I have seen one other app do this but have no idea how.
Many thanks.
12-11-2012 02:03 PM
I have been searching and searching for a solution to this and have found a possability.
https://developer.blackberry.com/cascades/referenc
I have not come accross QEvents but it does have a Keypress event. Anyone used this before?
12-14-2012 09:32 AM
Have managed to get numeric key presses working.
I created a javascript function as follows:
// Strips out non numeric characters allowing only 0-9 and '.'
function numericOnly (textin) {
var m_strOut = new String (textin);
m_strOut = m_strOut.replace(/[^\d.]/g,'');
return m_strOut;
} // end numericOnly
and then in the onTextChanging event did this:
onTextChanging: {
txtAmount.text = rootContainer.numericOnly(text);
}
Hope this helps someone.
12-14-2012 09:43 AM
Thanks!
12-14-2012 10:38 PM
there are more options with TextArea or TextField property inputMode, unfortunately I didn't see anything that limits to numeric only. the closest I found is TextFieldInputMode.Pin
inputMode : TextFieldInputMode.Pin
12-17-2012 06:38 AM
@vencedor: TextFieldInputMode determines, which kind of keyboard apperas. In this case i use "TextFieldInputMode.NumbersAndPunctuation", but unfortunally it still has has keys, i dont want the user to use.
01-04-2013 01:15 PM
Hi theappspod,
You're solution is very helpful but, for a weird reason, it seems possible to "break" the function.
The function works great for normal input situation, but i found out that if you spam the textfield with non-numeric characters the function could "break", allowing the user to enter non-numeric characters again and you have to restart the application for the function to work again.
Anyone has the same behavior or have a fix for this? On my side, I'm trying to look further into this and I'll post a solution if I ever find one.
I really hope RIM makes something for this because numeric only input field could be of use in a lot of applications.
01-19-2013 11:14 AM
For a currency field... here is was I use... that's until RIM come up with a Currency solution ![]()
// Strips out non numeric characters allowing only 0-9 and '.'
function currencyOnly(text)
{
// First clean and only keep numerics and .
var result = new String(text);
result = result.replace(/[^\d.]/g,'');
// Check if more then on . is inputted
if (text.split(".").length >= 3)
{
console.debug("Field must only have one .");
result = text.substring(0, text.length - 1);
}
// Next we verify that only two decial are keeped.
var decimal = text.indexOf(".");
if (decimal != -1)
{
if (decimal + 3 < text.length)
{
console.debug("Field must have only 2 decimal places");
result = text.substring(0, decimal + 3);
}
}
return result;
}
01-23-2013 03:38 PM
great! but how to allow users to input negative values too?