1 Reply Latest reply on Nov 28, 2014 5:59 PM by csa

    Data Binding: Force synchronization on keyup event.

    cpuffalt

      With Errai Data Binding is there anyway to trigger the databinder to synchronize bound widgets to the model on keyup?  As far as I can tell the documentation doesn't actually specify when synchronization happens but I assume it's done onBlur.  We have a usecase where we register a key event listener on one of our input fields so that we can trigger a server call when the ENTER key is hit.  Once we switched to using data binding of course we found the value hadn't been copied to our model.

       

      We've checked the DataBinder but didn't see any obvious method that we could call to force a sync, nor does there appear to be an option in the @Bound annotation to control this type of behaviour.  Is there any other way of achieving this? 


      For now this isn't a big deal, we've just stopped using Data Binding for the moment, but it would be nice to be able to address this type of use-case.

       

      Thanks,

      Corey

        • 1. Re: Data Binding: Force synchronization on keyup event.
          csa

          Hi Corey,

           

          UI changes are synced to the model using value change events. In the case you describe, it should be enough to do the following:

           

          inputField.addKeyUpHandler(new KeyUpHandler() {
                @Override
                public void onKeyUp(KeyUpEvent event) {
                  if(event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                    ValueChangeEvent.fire(inputField, inputField.getValue());
                    // trigger your server call
                  }
                }
          });
          
          

           

          or if you're using @Templated:

           

            @EventHandler("inputField")
            private void onKeyUp(KeyUpEvent e) {
              if(e.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                ValueChangeEvent.fire(inputField, inputField.getValue());
                // trigger your server call
              }
          }
          
          

           

          You're right that this would be a good feature to add though (configure the event to sync on). Do you want to create a JIRA for use with an API proposal? Of course, you're also welcome to send a pull request if you're interested.

           

          Cheers,

          Christian