Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Enable button on key press when valuesHaveChanged

    Hi,

    I'm trying to enable a save button on a key press event when DynamicForm.valuesHaveChanged() is true.

    This the code I have so far:
    Code:
    form.addItemKeyPressHandler(new ItemKeyPressHandler() {
        
        @Override
        public void onItemKeyPress(ItemKeyPressEvent event) {
            // Disable when values have not changed
            saveButton.setDisabled(!form.valuesHaveChanged());
        }
    });
    With the above code, when I type a single character in the item, the save button is disabled still. However, when I type a second character, the save button is enabled. This leads me to believe the values aren't compared (or the valuesHaveChanged() method doesn't have access to the new values) until after handling the key press event.

    Is there a way for the key press event to be handled after the values are compared?

    Thanks in advance!

    #2
    FYI, I tried to add handlers for KeyDown, KeyPress, and ItemChange with similar results.

    Comment


      #3
      All of those events occur before the change and can be cancelled to cancel the event or change. ItemChanged (ends with a D) occurs after the change.

      Comment


        #4
        I tried ItemChangedEvent but an ItemChangedEvent doesn't occur until the user changes and then unfocuses out of the item. We want the button enabled right when the user enters any input.

        Comment


          #5
          Both granularities are supported - setChangeOnKeypress(true) to make change fired per-keyPress.

          Comment


            #6
            Thank you! I called setChangeOnKeypress(true) on my FormItems and added an ItemChangedHandler to my DynamicForm. Works great now.

            Comment

            Working...
            X