Results 1 to 6 of 6

Thread: TextField With Validator and echoMode Set to TextInput Password

  1. #1
    Join Date
    Apr 2015
    Posts
    20
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default TextField With Validator and echoMode Set to TextInput Password

    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.

    Qt Code:
    1. TextTield {
    2. id: rowField
    3. echoMode: index===4 || index===5 ? TextInput.Password : TextInput.Normal
    4. text: modeltext
    5. valFail: ((!acceptableInput && focus) ? true : false)
    6. property var valid0: RegExpValidator { regExp: /.*/ }
    7. property var valid1: RegExpValidator { regExp: /.*/ }
    8. property var valid2: RegExpValidator { regExp: /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ }
    9. property var valid3: RegExpValidator { regExp: /.{6,}/ }
    10. property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[a-zA-Z\d@$!%*?&]{8,32}$/ }
    11. property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[a-zA-Z\d@$!%*?&]{8,32}$/ }
    12. property var valid6: RegExpValidator { regExp: /.*/ }
    13. validator:
    14. if(index === 1) {valid1}
    15. else if(index === 2) {valid2}
    16. else if(index === 3) {valid3}
    17. else if(index === 4) {valid4}
    18. else if(index === 5) {valid5}
    19. else if(index === 6) {valid6}
    20. else{valid0}
    To copy to clipboard, switch view to plain text mode 


    Any insight appreciated!

    Thanks,
    -Rich

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TextField With Validator and echoMode Set to TextInput Password

    If you don't put any validator on those fields, are you able to type into them?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2015
    Posts
    20
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: TextField With Validator and echoMode Set to TextInput Password

    Did not try that but I can type and see '*' in the field with / ^.*$ / as the validator regex.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TextField With Validator and echoMode Set to TextInput Password

    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?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2015
    Posts
    20
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: TextField With Validator and echoMode Set to TextInput Password

    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.
    Qt Code:
    1. echoMode: index===5 ? TextInput.Password : TextInput.Normal
    2. text: modeltext
    3. valFail: ((!acceptableInput && focus) ? true : false)
    4. visible: index===6 ? false : true
    5. property var valid0: RegExpValidator { regExp: /^.{0,32}$/ }
    6. property var valid1: RegExpValidator { regExp: /^.{0,32}$/ }
    7. property var valid2: RegExpValidator { regExp: /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ }
    8. property var valid3: RegExpValidator { regExp: /^.{6,32}$/ }
    9. //property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W).{8,32}$/ }
    10. //property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W).{8,32}$/ }
    11. property var valid4: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z]).*$/ }
    12. property var valid5: RegExpValidator { regExp: /^(?=.*[a-z])(?=.*[A-Z]).*$/ }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. property var valid4: RegExpValidator { regExp: /^(?=.*[0-9]).*$/ }
    2. property var valid5: RegExpValidator { regExp: /^(?=.*[0-9]).*$/ }
    To copy to clipboard, switch view to plain text mode 


    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!
    Last edited by rhb327; 9th May 2020 at 17:04.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TextField With Validator and echoMode Set to TextInput Password

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 13th May 2019, 17:25
  2. Replies: 0
    Last Post: 22nd September 2016, 22:23
  3. TextField Completer
    By folibis in forum Qt Quick
    Replies: 1
    Last Post: 23rd December 2013, 13:44
  4. How can i have echomode in QtableView for password column?
    By WinterIsComing in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2013, 11:09
  5. QLineEdit and EchoMode Passowrd
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2009, 18:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.