Tapestry
  1. Tapestry
  2. TAPESTRY-2324

Wrong Submit 'selected' event fired when using a Form with a Zone parameter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.12
    • Fix Version/s: 5.0.15
    • Component/s: Core Components
    • Labels:
      None
    • Environment:
      Jetty 5.1.12; Tapestry 5.0.12-SNAPSHOT

      Description

      Given the following code:
      void onSelectedFromSave()
      {
      System.out.println("save");
      }

      void onSelectedFromCancelChanges()
      {
      System.out.println("cancel");
      }

      The following template outputs 'save' when clicking on the save button and 'cancel' when clicking on the cancel button
      <t:form t:id="finalizeChanges" zone="testZone">
      <t:submit t:id="save"/>
      <t:submit t:id="cancelChanges"/>
      </t:form>

      The following template/code outputs 'save' when clicking on the save button and 'save' when clicking on the cancel button
      <t:zone t:id="testZone">
      <t:form t:id="finalizeChanges" zone="testZone">
      <t:submit t:id="save"/>
      <t:submit t:id="cancelChanges"/>
      </t:form>
      </t:zone>

      The following template/code outputs 'cancel' when clicking on the save button and 'cancel' when clicking on the cancel button
      <t:zone t:id="testZone">
      <t:form t:id="finalizeChanges" zone="testZone">
      <t:submit t:id="cancelChanges"/>
      <t:submit t:id="save"/>
      </t:form>
      </t:zone>

      1. TAPESTRY-2324.patch
        2 kB
        Ben Sommerville
      2. TAPESTRY-2324_r686911.patch
        3 kB
        Filip S. Adamsen
      3. Tapestry-2324_5.0.14.patch
        3 kB
        Filip S. Adamsen

        Issue Links

          Activity

          Peter Beshai created issue -
          Hide
          Adriaan Joubert added a comment -

          Problem seems to be that when serialising the form components prototype simply picks the first submit button. So the wrong id is returned in the Ajax request (always the id of the first button that is encountered).

          I do have a second problem as well: no selected event is issued at all. Peter's example indicates that he is getting selected events, but I only get an onSuccess. When taking the zone out everything works fine, so this is not a simple typing error.

          Cheers,

          Adriaan

          Show
          Adriaan Joubert added a comment - Problem seems to be that when serialising the form components prototype simply picks the first submit button. So the wrong id is returned in the Ajax request (always the id of the first button that is encountered). I do have a second problem as well: no selected event is issued at all. Peter's example indicates that he is getting selected events, but I only get an onSuccess. When taking the zone out everything works fine, so this is not a simple typing error. Cheers, Adriaan
          Hide
          Martin Wiesinger added a comment -

          I do have to report the same behavior in version: 5.0.11
          A request triggers always the first onSelected event it encounters.

          Greets,
          Martin

          Show
          Martin Wiesinger added a comment - I do have to report the same behavior in version: 5.0.11 A request triggers always the first onSelected event it encounters. Greets, Martin
          Hide
          Ben Sommerville added a comment -

          Patch fixes issue by observing the click event of all submit buttons within a (zone) form and saving the name of the button that is clicked. The submit handler then passes that name to the form.request call as an option.

          This fix also required patching prototype to properly pass on the submit option to the form serialize method. A prototype bug has been logged as:
          http://prototype.lighthouseapp.com/projects/8886-prototype/tickets/66-form-request-does-not-pass-options-to-form-serialize

          Show
          Ben Sommerville added a comment - Patch fixes issue by observing the click event of all submit buttons within a (zone) form and saving the name of the button that is clicked. The submit handler then passes that name to the form.request call as an option. This fix also required patching prototype to properly pass on the submit option to the form serialize method. A prototype bug has been logged as: http://prototype.lighthouseapp.com/projects/8886-prototype/tickets/66-form-request-does-not-pass-options-to-form-serialize
          Ben Sommerville made changes -
          Field Original Value New Value
          Attachment TAPESTRY-2324.patch [ 12381239 ]
          Hide
          Filip S. Adamsen added a comment -

          Attached Ben Sommerville's patch updated for Tapestry 5.0.14. I can confirm that this solves the issue.

          Show
          Filip S. Adamsen added a comment - Attached Ben Sommerville's patch updated for Tapestry 5.0.14. I can confirm that this solves the issue.
          Filip S. Adamsen made changes -
          Attachment Tapestry-2324_5.0.14.patch [ 12388485 ]
          Hide
          Filip S. Adamsen added a comment -

          Attached Ben Sommerville's patch updated for r686911.

          Show
          Filip S. Adamsen added a comment - Attached Ben Sommerville's patch updated for r686911.
          Filip S. Adamsen made changes -
          Attachment TAPESTRY-2324_r686911.patch [ 12388486 ]
          Hide
          Filip S. Adamsen added a comment -

          It would be great if this could make it into 5.0.15.

          Show
          Filip S. Adamsen added a comment - It would be great if this could make it into 5.0.15.
          Howard M. Lewis Ship made changes -
          Assignee Howard M. Lewis Ship [ hlship ]
          Howard M. Lewis Ship made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          Howard M. Lewis Ship added a comment -

          I'm looking for a way that this will work without further patches to prototype.

          Also, I'm concerned that an Ajax update that injects new content into the form will add further submit elements that won't have their click even tracked. So the code that attaches that event handler needs to go inside onDomLoadedCallback().

          Show
          Howard M. Lewis Ship added a comment - I'm looking for a way that this will work without further patches to prototype. Also, I'm concerned that an Ajax update that injects new content into the form will add further submit elements that won't have their click even tracked. So the code that attaches that event handler needs to go inside onDomLoadedCallback().
          Hide
          Howard M. Lewis Ship added a comment -

          You can definitely see that the problem is with Prototype. It is serializing just the first submit it sees, regardless of which submit was clicked. We need to override how the form is serialized to remove keys for submits that are not the active submit, and ensure that the value for the active submit is actually submitted.

          Show
          Howard M. Lewis Ship added a comment - You can definitely see that the problem is with Prototype. It is serializing just the first submit it sees, regardless of which submit was clicked. We need to override how the form is serialized to remove keys for submits that are not the active submit, and ensure that the value for the active submit is actually submitted.
          Show
          Howard M. Lewis Ship added a comment - Related: http://prototype.lighthouseapp.com/projects/8886/tickets/66-form-request-does-not-pass-options-to-form-serialize
          Howard M. Lewis Ship committed 692587 (1 file)
          Reviews: none

          TAPESTRY-2324: Wrong Submit 'selected' event fired when using a Form with a Zone parameter

          Hide
          Howard M. Lewis Ship added a comment -

          Upgrade to Prototype 1.6.0.2 while I was working everything over.

          Show
          Howard M. Lewis Ship added a comment - Upgrade to Prototype 1.6.0.2 while I was working everything over.
          Howard M. Lewis Ship made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Fix Version/s 5.0.15 [ 12313350 ]
          Resolution Fixed [ 1 ]
          Howard M. Lewis Ship committed 692588 (1 file)
          Reviews: none

          TAPESTRY-2324: Wrong Submit 'selected' event fired when using a Form with a Zone parameter

          Howard M. Lewis Ship committed 692589 (1 file)
          Reviews: none

          TAPESTRY-2324: Wrong Submit 'selected' event fired when using a Form with a Zone parameter

          Josh Canfield made changes -
          Link This issue relates to TAP5-1418 [ TAP5-1418 ]
          Mark Thomas made changes -
          Workflow jira [ 12427994 ] Default workflow, editable Closed status [ 12567051 ]
          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12567051 ] jira [ 12589794 ]

            People

            • Assignee:
              Howard M. Lewis Ship
              Reporter:
              Peter Beshai
            • Votes:
              8 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development