Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-2324

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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_r686911.patch
        3 kB
        Filip S. Adamsen
      2. Tapestry-2324_5.0.14.patch
        3 kB
        Filip S. Adamsen
      3. TAPESTRY-2324.patch
        2 kB
        Ben Sommerville

        Issue Links

          Activity

          Hide
          hlship Howard M. Lewis Ship added a comment -

          Upgrade to Prototype 1.6.0.2 while I was working everything over.

          Show
          hlship Howard M. Lewis Ship added a comment - Upgrade to Prototype 1.6.0.2 while I was working everything over.
          Show
          hlship 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
          Hide
          hlship 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
          hlship 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.
          Hide
          hlship 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
          hlship 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
          fsa Filip S. Adamsen added a comment -

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

          Show
          fsa Filip S. Adamsen added a comment - It would be great if this could make it into 5.0.15.
          Hide
          fsa Filip S. Adamsen added a comment -

          Attached Ben Sommerville's patch updated for r686911.

          Show
          fsa Filip S. Adamsen added a comment - Attached Ben Sommerville's patch updated for r686911.
          Hide
          fsa 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
          fsa 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.
          Hide
          bpsommerville 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
          bpsommerville 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
          Hide
          mateu 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
          mateu 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
          adriaanjoubert 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
          adriaanjoubert 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

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development