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 Developer
Posts: 17
Registered: ‎07-16-2012
My Device: None
My Carrier: None

QML Form Validation

Hi all,

 

How would you go about doing form validation, as i cant find any article on this?

 

For example validating numbers only.

 

TextField {
           id: amount
           inputMode: TextFieldInputMode.Text
           hintText: "Only Numbers Allowed"
           text:""
           input {
                onSubmitted: {
                    //...Perform action on submission...
                }
            }
           
       }

Developer
Posts: 426
Registered: ‎04-10-2011
My Device: Z30

Re: QML Form Validation

Why don't you use the inputMode for number validation?

inputMode: TextFieldInputMode.NumbersAndPunctuation

This should show a numbers only keyboard and will probably only allow numbers on hardware-keyboard-devices.

-----------------------------------------------------------------------------
Check out my apps in the BlackBerry World
Visit my developer blog alopix.net
BBM Channel: C0047B612
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QML Form Validation

Setting inputMode won't help as the text still can be pasted.

 

For validation I usually create a custom control with TextField (or other components) and invisible label for validation text.

When the form is submitted, validate the values then update labels with validation text where appropriate, setting their 'visible' property to true.

 

You can also subscribe to TextField's signals such as onTextChanging to validate the text and show hints during editing.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 426
Registered: ‎04-10-2011
My Device: Z30

Re: QML Form Validation

Almost forgot about copy&paste.

Is this input.onSubmitted working? QDE doesn't validate my qml file when having this event-handler Smiley Sad
-----------------------------------------------------------------------------
Check out my apps in the BlackBerry World
Visit my developer blog alopix.net
BBM Channel: C0047B612
Contributor
Posts: 20
Registered: ‎02-21-2012
My Device: Bold 9900
My Carrier: AT&T

Re: QML Form Validation

onTextChanged also works for copying and pasting. onTextChanging is per letter, so you can use this for auto-completion.

You could create a JavaScript function that simply fails if (input.text fails the JavaScript regex).
Developer
Posts: 180
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: QML Form Validation

What about text length validations? On the Roadmap page it states Length Validations were added in C5 release in December, yet I cannot find any properties on the TextField control to control the length nor any mention of this in the documentation. Am i missing something here?

 

"Ability to set text length restrictions on Cascades input controls. (Delayed from Beta 4 release, re-scheduled for Gold release)"

---
If you find my post helpful please "like" it and "accept as a solution"