Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-71055

Text is not validated when replacing selected text by typing

    XMLWordPrintable

Details

    Description

      From customer:

      Im expecting the the programmatically set value to ignored the validator, but I need the first press on virtual keyboard to not be ignored. 

      TextField{ 
      id: m_editLine 
      inputMethodHints:Qt.ImhUppercaseOnly 
      validator: RegExpValidator {regExp: /[A-F0-9]{8}} 

      The TextField is programmatically set to a value outside the validators regex ("Activation Code"), and the text is selected programmatically. 

      function programmaticSet(msg)

      {  m_editLine.text = msg;  m_editLine.selectAll();  }

       

      The keyboard is setting to all uppercase, but the issue is that if the first key pressed is not in the validators regex, the validator is ignored and any input is allowed. 
      If the first key pressed from the virtual keyboard is in the validators regex it will be enforced. 

       

      From support

      When text has been set programmatically in TextInput and then selected, as the user starts to type text, validator doesn't start validating the text if the first character is not acceptable. If the first typed character is acceptable validating works correctly. This was reported as happening with virtualkeyboard, but I was also able to reproduce this with normal keyboard.

      Here's my example code that has also workaround in comments:

       

      import QtQuick 2.2
      import QtQuick.VirtualKeyboard 2.1
      import "content"
      
      Rectangle {
          Component.onCompleted: {
              programmaticSet("Ready for input")
              m_editLine.forceActiveFocus();
          }
      
          function programmaticSet(msg){
              //m_editLine.inputMask = "";
              m_editLine.text = msg;
              m_editLine.selectAll();
          }
          width: 640
          height: 480
          color: "#F6F6F6"
      
          TextInput {
              id: m_editLine
              x: 50
              y: 50
              height: 100
              width: parent.width
              inputMethodHints:Qt.ImhUppercaseOnly
              validator: RegExpValidator {regExp: /[A-F0-9]{8}/}
              /*
              onSelectedTextChanged: {
                  if (focus && text.length === 1 )
                  {
                      inputMask = ">HHHHHHHH";
                      if (text.length > 0)
                          select(1,1);
                  }
              }
              */
          }
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kari.oikarinen Kari Oikarinen
            izero Tero Siironen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes