Wicket
  1. Wicket
  2. WICKET-5194

Adding AjaxFormValidatingBehavior to the form prevents form from being filled

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.8.0
    • Fix Version/s: 6.9.0
    • Component/s: wicket
    • Labels:
      None

      Description

      It is impossible to enter any text in the form fields in case

      AjaxFormValidatingBehavior.addToAllFormComponents(form, "keydown", Duration.ONE_SECOND);

      was added.

      Everything works as expected in 6.7.0

      1. WICKET-5194.patch
        11 kB
        Martin Grigorov
      2. WICKET-5178.patch
        0.6 kB
        Andrea Del Bene
      3. AjaxFormValBehavior.zip
        32 kB
        Andrea Del Bene

        Issue Links

        There are no Sub-Tasks for this issue.

          Activity

          Hide
          Martin Grigorov added a comment -

          Andrea's patch is applied.

          Show
          Martin Grigorov added a comment - Andrea's patch is applied.
          Hide
          Martin Grigorov added a comment -

          A patch that sets 'allowDefault' default value to 'true'.

          Show
          Martin Grigorov added a comment - A patch that sets 'allowDefault' default value to 'true'.
          Hide
          Martin Grigorov added a comment -

          Indeed there is a problem with 'allowDefault' default value being 'false'.
          Andrea's quickstart shows that <input type="text" ../> + 'key(down|up)' event doesn't work unless 'allowDefault=true' is set explicitly.

          To avoid overriding #updateAjaxAttributes(AjaxRequestAttributes attributes) for each and every Ajax behavior in your app one can do:

          getAjaxRequestTargetListeners().add(new AjaxRequestTarget.AbstractListener()
          {
          @Override
          public void updateAjaxAttributes(AjaxRequestAttributes attributes)

          { super.updateAjaxAttributes(attributes); attributes.setAllowDefault(true); }

          });

          in MyApp#init().

          I'll raise this problem in dev@.

          Show
          Martin Grigorov added a comment - Indeed there is a problem with 'allowDefault' default value being 'false'. Andrea's quickstart shows that <input type="text" ../> + 'key(down|up)' event doesn't work unless 'allowDefault=true' is set explicitly. To avoid overriding #updateAjaxAttributes(AjaxRequestAttributes attributes) for each and every Ajax behavior in your app one can do: getAjaxRequestTargetListeners().add(new AjaxRequestTarget.AbstractListener() { @Override public void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); attributes.setAllowDefault(true); } }); in MyApp#init(). I'll raise this problem in dev@.
          Hide
          Sven Meier added a comment -

          Andrea's patch looks fine to me. It's not exactly the old behavior though, as previously any event without throttle delay would not have allowed the default.

          Show
          Sven Meier added a comment - Andrea's patch looks fine to me. It's not exactly the old behavior though, as previously any event without throttle delay would not have allowed the default.
          Hide
          Andrea Del Bene added a comment -

          I've attached a quickstart. It's quite simple: you have fields 'name' and 'surname'. The first has the same AjaxEventBehavior reported in my last post and you can not edit a value in it.

          Show
          Andrea Del Bene added a comment - I've attached a quickstart. It's quite simple: you have fields 'name' and 'surname'. The first has the same AjaxEventBehavior reported in my last post and you can not edit a value in it.
          Hide
          Sven Meier added a comment -

          Prior to Wicket 6.8.0 a event default was not prevented, when the Ajax request was throttled. The old behavior was a bug: If a developer wants the default event to be prevented, it should do so whether the request is throttled or not.

          We'll have to fix AjaxFormValidatingBehavior#addToAllFormComponents() now.

          Show
          Sven Meier added a comment - Prior to Wicket 6.8.0 a event default was not prevented, when the Ajax request was throttled. The old behavior was a bug: If a developer wants the default event to be prevented, it should do so whether the request is throttled or not. We'll have to fix AjaxFormValidatingBehavior#addToAllFormComponents() now.
          Hide
          Martin Grigorov added a comment -

          I cannot find any problem with Ajax in our app and with Wicket-Examples.
          Please create a quickstart and attach it here.
          Thanks!

          Show
          Martin Grigorov added a comment - I cannot find any problem with Ajax in our app and with Wicket-Examples. Please create a quickstart and attach it here. Thanks!
          Hide
          Andrea Del Bene added a comment - - edited

          Yes, behavior still be as in 6.6.0. The point is that from ver 6.7.0 to 6.8.0 function Wicket.Ajax.ajax has been changed adding 'Wicket.Ajax._handleEventCancelation(attributes)' which by default invokes 'evt.preventDefault()'. This last invocation is controlled by attribute AjaxRequestAttributes.allowDefault which is false by default.
          In short with ver 6.8.0 every event-based AJAX behavior prevent the default event handling by default. If we try to use an AjaxEventBehavior like this:

          textfield.add(new AjaxEventBehavior("keydown") {

          @Override
          protected void onEvent(AjaxRequestTarget target) {

          }
          });

          we obtain the same issue described here (the textfield is not editable).

          Show
          Andrea Del Bene added a comment - - edited Yes, behavior still be as in 6.6.0. The point is that from ver 6.7.0 to 6.8.0 function Wicket.Ajax.ajax has been changed adding 'Wicket.Ajax._handleEventCancelation(attributes)' which by default invokes 'evt.preventDefault()'. This last invocation is controlled by attribute AjaxRequestAttributes.allowDefault which is false by default. In short with ver 6.8.0 every event-based AJAX behavior prevent the default event handling by default. If we try to use an AjaxEventBehavior like this: textfield.add(new AjaxEventBehavior("keydown") { @Override protected void onEvent(AjaxRequestTarget target) { } }); we obtain the same issue described here (the textfield is not editable).
          Hide
          Martin Grigorov added a comment -

          What do you mean ?

          In 6.7.0 we added a property in AjaxRequestAttributes for JS event.stopPropagation() so now you can control it like you were able for event.preventDefault().

          Additionally we moved the call to preventDefault/stopPropagation in code that is not throttled so they are always executed.

          The behavior should be as in 6.6.0 but it seems indeed something is different thus this ticket.

          Show
          Martin Grigorov added a comment - What do you mean ? In 6.7.0 we added a property in AjaxRequestAttributes for JS event.stopPropagation() so now you can control it like you were able for event.preventDefault(). Additionally we moved the call to preventDefault/stopPropagation in code that is not throttled so they are always executed. The behavior should be as in 6.6.0 but it seems indeed something is different thus this ticket.
          Hide
          Andrea Del Bene added a comment -

          The problem is bigger as it affects also AjaxEventBehavior

          Show
          Andrea Del Bene added a comment - The problem is bigger as it affects also AjaxEventBehavior
          Hide
          Andrea Del Bene added a comment -

          We should set the default behavior flag to true for AjaxFormValidatingBehavior. See patch.

          Show
          Andrea Del Bene added a comment - We should set the default behavior flag to true for AjaxFormValidatingBehavior. See patch.
          Hide
          Andrea Del Bene added a comment -

          Event cancellation has been added at line 1819 of wicket-ajax-jquery.js. I'm tracking back the commit that introduced this instruction.

          Show
          Andrea Del Bene added a comment - Event cancellation has been added at line 1819 of wicket-ajax-jquery.js. I'm tracking back the commit that introduced this instruction.

            People

            • Assignee:
              Martin Grigorov
              Reporter:
              Maxim Solodovnik
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development