PDA

View Full Version : TextField With Validator and echoMode Set to TextInput Password



rhb327
8th May 2020, 22:42
I'm having issue using both TextField with echoMode set to TextInput.Password and a validator. I'm unable to type into either the index 4 or 5 box! So my regex is either wrong but works in a calculator or somethings up with echoMode.


TextTield {
id: rowField
echoMode: index===4 || index===5 ? TextInput.Password : TextInput.Normal
text: modeltext
valFail: ((!acceptableInput && focus) ? true : false)
property var valid0: RegExpValidator { regExp: /.*/ }
property var valid1: RegExpValidator { regExp: /.*/ }
property var valid2: RegExpValidator { regExp: /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ }
property var valid3: RegExpValidator { regExp: /.{6,}/ }
property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[a-zA-Z\d@$!%*?&]{8,32}$/ }
property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[a-zA-Z\d@$!%*?&]{8,32}$/ }
property var valid6: RegExpValidator { regExp: /.*/ }
validator:
if(index === 1) {valid1}
else if(index === 2) {valid2}
else if(index === 3) {valid3}
else if(index === 4) {valid4}
else if(index === 5) {valid5}
else if(index === 6) {valid6}
else{valid0}


Any insight appreciated!

Thanks,
-Rich

d_stranz
8th May 2020, 23:27
If you don't put any validator on those fields, are you able to type into them?

rhb327
8th May 2020, 23:36
Did not try that but I can type and see '*' in the field with / ^.*$ / as the validator regex.

d_stranz
9th May 2020, 00:32
I'm wondering whether the validator is acting on the text you type or the "***" it is getting replaced with. If you go back to your original regex and turn off the password flag, does it work then?

rhb327
9th May 2020, 16:07
No joy yet. I've been testing with index 4 & 5 and you can see one is TextInput.Normal and the other is TextInput.Password. Both have the same regex and neither allows any entry into the field! It seem as soon as I have 2x lookaheads I struggle.


echoMode: index===5 ? TextInput.Password : TextInput.Normal
text: modeltext
valFail: ((!acceptableInput && focus) ? true : false)
visible: index===6 ? false : true
property var valid0: RegExpValidator { regExp: /^.{0,32}$/ }
property var valid1: RegExpValidator { regExp: /^.{0,32}$/ }
property var valid2: RegExpValidator { regExp: /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ }
property var valid3: RegExpValidator { regExp: /^.{6,32}$/ }
//property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W).{8,32}$/ }
//property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W).{8,32}$/ }
property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z]).*$/ }
property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z]).*$/ }

This simple case seems to work...enter anything and when you have a number it's validated. Number does not have to be first.


property var valid4: RegExpValidator { regExp: /^(?=.*[0-9]).*$/ }
property var valid5: RegExpValidator { regExp: /^(?=.*[0-9]).*$/ }

Added after 12 minutes:

I'm thinking there's no way to do this accept a post check. From the help file:


When a validator is set the TextInput will only accept input which leaves the text property in an acceptable or intermediate state. The accepted signal will only be sent if the text is in an acceptable state when enter is pressed.

So how can you leave the text in an intermediate state when you require more than one character and can only enter one character at a time?

So for my full up regex (commented out above). I can paste in with: aA1&. I can not past in with: aA11.

And on the first one....I cannot delete any of the characters. So it seems a post check will be required!

d_stranz
9th May 2020, 16:53
So it seems a post check will be required!

Either that or write your own validator that can handle the lookaheads. It isn't that hard - I've written a validator that accepts only properly formatted chemical formulas using a custom parser as a back end.