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
Highlighted
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia
Accepted Solution

Replace a string in QML

I want to input a float number like 3.42 in a textbox.

The problem is that the number keyboard doesn't have the period, so I wanted to do a simple stuff like this on onChanged:

 

var mytext = textfield.text;
mytext.replace("*",".");
textfield.text = mytext;

 (so the user could use * as a period for decimals)

But it doesn't work. String.replace isn't supported in QML? Or I'm doing something wrong?

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Replace a string in QML

Hi!
It returns a copy, try:
mytext = mytext.replace("*", ".")

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Replace a string in QML

lol i'm an **bleep**.
thanks
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Replace a string in QML

I share the regex that "converts" the extra "useless" keys to periods in TextFieldInputMode.PhoneNumber

 

mytext = mytext.replace(/[()w\-+p\*#]/,".");

 

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

Re: Replace a string in QML

Magnetic_dud, a couple of comments:

1. You asked how to do this "in QML", but you should know you're doing it in JavaScript (which just happens to be contained inside a .qml file). Any tutorial or reference on the web for JavaScript will be relevant, provided you ignore the APIs which are specific to web browsers.

2. Users will probably find your use of the PhoneNumber keypad surprising for numeric data entry. We'd really all like a calculator keypad, but instead, we have TextFieldInputMode.NumbersAndPunctuation. Best to use that, since it's the standard on this platform and what users will be used to.

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
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Replace a string in QML

yes... it's standard js, but it didn't worked so i just messed up.... i'm ashamed...

but TextFieldInputMode.NumbersAndPunctuation shows a lot of useless characters + number keys are very small
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Replace a string in QML

I agree with those observations, but still think users will find it awkward. Other devs may disagree... I don't think any of us have actually done usability studies to investigate this though. Smiley Happy

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
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Replace a string in QML

but, if they don't discover (i explained why and how in help page), they can still press "abc" and insert the period in the normal keyboard
plus, it's less likely to insert a non number Smiley Wink
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Replace a string in QML

You do what you feel is reasonable. I'm just describing a basic usability principle, which is "Don't surprise the user".

Also note that although people are used to the phone keypad layout for entering phone numbers, they are used to the different calculator keypad layout for entering other types of numeric data. They'll have that extra bit of hesitation and (perhaps subconscious) awkwardness when they get to your app and start entering numbers as though they were dialing a phone.

Maybe at least experiment with both and give it to some real users to test, and adjust if required based on their feedback.

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!