Pivot
  1. Pivot
  2. PIVOT-612

TextInput validator problem when modifying selected text

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.5.2, 2.0
    • Component/s: None
    • Labels:
      None

      Description

      I have a validator on a textinput with strict validation set to true;
      The validator tries to match the text against a pattern.
      Everything is fine until i try to modify text that is selected (either partially or completely).
      And this because validation does not take into account that selected text should be replaced by typed characters;
      instead, it is trying to validate the concatenation of the new character and the actual text instead of replacing the selected part of the text.
      (lines 1059-1063 in class TerraTextInputSkin)
      I don't know if I'm clear.

      Consider this (pretty stupid) example that tries to accept only one digit in the text input :

      TextInput textInput = new TextInput();
      textInput.setMaximumLength(1);
      textInput.setStrictValidation(true);
      textInput.setValidator(new Validator() {
      @Override
      public boolean isValid(String text)

      { if (text.length() == 0) return true; // ok we accept empty field return text.length() == 1 && Character.isDigit(text.charAt(0)); }

      });

      BoxPane boxPane = new BoxPane(Orientation.HORIZONTAL);
      boxPane.add(textInput);
      boxPane.add(new PushButton("Test"));
      window.setContent(boxPane);

      Steps:
      1. start app.
      2. put focus in textinput (should be empty)
      3. enter a digit, ex : '5'; ok this should work
      4. move focus on button then move focus back on textinput
      5. text is selected in textinput
      6. try to replace the selected value ('5') by another digit by simply typing it
      ==> doesnt work (while it should)

        Activity

        Hide
        Bojan Vucinic added a comment -

        I have solved the problem by checking for empty string and catching an exception.
        Example (in Scala):
        if (textIn.getText != "" && textIn.isValid) {
        try

        {m.putDensity(textIn.getText.toDouble) textOut.setText("" + m.volume) tOut.setText("" + m.mass)}

        catch

        { case e:java.lang.NumberFormatException => println("Not a number!") }

        }

        Show
        Bojan Vucinic added a comment - I have solved the problem by checking for empty string and catching an exception. Example (in Scala): if (textIn.getText != "" && textIn.isValid) { try {m.putDensity(textIn.getText.toDouble) textOut.setText("" + m.volume) tOut.setText("" + m.mass)} catch { case e:java.lang.NumberFormatException => println("Not a number!") } }
        Hide
        Bojan Vucinic added a comment -

        I have a similar problem:
        I have defined a DoubleRangeValidator, as:
        hfoDensity.setValidator(new DoubleRangeValidator(0.5, 1.1))
        If I select the TextInput the first character I type is disregarded, it is not until the second that the selection is replaced.

        Show
        Bojan Vucinic added a comment - I have a similar problem: I have defined a DoubleRangeValidator, as: hfoDensity.setValidator(new DoubleRangeValidator(0.5, 1.1)) If I select the TextInput the first character I type is disregarded, it is not until the second that the selection is replaced.
        Greg Brown made changes -
        Fix Version/s 1.5.2 [ 12315227 ]
        Noel Grandin made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0 [ 12313780 ]
        Resolution Fixed [ 1 ]
        A.J. created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            A.J.
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development