Tapestry 5
  1. Tapestry 5
  2. TAP5-1859

Clicking a submit or button in a non-Tapestry Form causes a client exception

    Details

      Description

      When submitting a html form which was not constructed using the tapestry Form component, tapestry.js still attempts to acquire a Tapestry.FormEventManager, resulting in an uncaught JS exception.

      TML test case:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns="tapestry:parameter">
      <t:zone t:id="dum" /><!-- make sure js is loaded into page -->
      <head></head>
      <body>
      <form>
      <input type="submit" />
      </form>
      </body>
      </html>

      Excerpt from tapestry.js:

      getFormEventManager : function(form) {
      form = $(form);

      var manager = $T(form).formEventManager;

      if (manager == undefined) {

      throw "No Tapestry.FormEventManager object has been created for form '#

      {id}

      '."
      .interpolate(form);
      }

      return manager;
      },

      is called by:

      setSubmittingElement : function(form, element)

      { form.getFormEventManager() .setSubmittingElement(element); }

      ,

      is called by:

      /*

      • When a submit element is clicked, record the name of the element into
      • the associated form. This is necessary for some Ajax processing, see
      • TAPESTRY-2324.
        *
      • TAP5-1418: Added "type=image" so that they set the submitting element
      • correctly.
        */
        $$("INPUT[type=submit]", "INPUT[type=image]").each(function(element) {
        var t = $T(element);

      if (!t.trackingClicks) {
      element.observe("click", function()

      { $(element.form).setSubmittingElement(element); }

      );

      t.trackingClicks = true;
      }
      });

      The solution is probably to add a check within this last snippet to make sure you are dealing with a tapestry form:

      // skip if this is not a tapestry controlled form
      if (this.form.getInputs("hidden", "t:formdata").size() == 0)
      return;

      The above is taken from elsewhere in tapestry.js.

        Activity

        Hide
        Howard M. Lewis Ship added a comment -

        Based on the work that's already gone on in 5.4, I don't think this bug affects that code anymore; for example, there is no FormEventManager anymore.

        Show
        Howard M. Lewis Ship added a comment - Based on the work that's already gone on in 5.4, I don't think this bug affects that code anymore; for example, there is no FormEventManager anymore.
        Hide
        Howard M. Lewis Ship added a comment -

        Why ever would you have forms that aren't Tapestry forms?

        Show
        Howard M. Lewis Ship added a comment - Why ever would you have forms that aren't Tapestry forms?
        Hide
        Paul Stanton added a comment -

        Here's a workaround - to avoid tapestry adding its click listener to the submit, set the flag before tapestry has a chance (before onDomLoaded)

        <form>
        <input type="submit" id="theSubmit" />
        </form>

        <script type="text/javascript">
        var t = $T("theSubmit");
        t.trackingClicks = true;
        </script>

        Show
        Paul Stanton added a comment - Here's a workaround - to avoid tapestry adding its click listener to the submit, set the flag before tapestry has a chance (before onDomLoaded) <form> <input type="submit" id="theSubmit" /> </form> <script type="text/javascript"> var t = $T("theSubmit"); t.trackingClicks = true; </script>

          People

          • Assignee:
            Howard M. Lewis Ship
            Reporter:
            Paul Stanton
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development