You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2021/04/05 19:44:15 UTC

[tapestry-5] branch master updated: TAP5-2669: Tapestry Form.js running on non Tapestry forms

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/master by this push:
     new f17f35c  TAP5-2669: Tapestry Form.js running on non Tapestry forms
f17f35c is described below

commit f17f35c1235ba93cb83a88d7f74757aa73e54a70
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Mon Apr 5 16:43:31 2021 -0300

    TAP5-2669: Tapestry Form.js running on non Tapestry forms
---
 .../coffeescript/META-INF/modules/t5/core/forms.coffee   | 10 ++++++++--
 .../org/apache/tapestry5/corelib/components/Form.java    | 16 +++++++++++++++-
 tapestry-core/src/test/app1/ClientFormatDemo.tml         |  6 ++++++
 .../integration/app1/pages/ClientFormatDemo.java         | 16 ++++++++++++++++
 4 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
index c8de264..6ebd9c2 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
@@ -22,6 +22,12 @@ define ["./events", "./dom", "underscore"],
     # Meta-data name that indicates the next submission should skip validation (typically, because
     # the form was submitted by a "cancel" button).
     SKIP_VALIDATION = "t5:skip-validation"
+    
+    # Data attribute and value added to HTML forms generated by the 
+    # Tapestry's Form component from the core library.
+    DATA_ATTRIBUTE = "data-generator"
+    DATA_ATTRIBUTE_VALUE = "tapestry/core/form"
+    TAPESTRY_CORE_FORM_SELECTOR = "form[" + DATA_ATTRIBUTE + "='" + DATA_ATTRIBUTE_VALUE + "']"
 
     clearSubmittingHidden = (form) ->
       hidden = form.findFirst "[name='t:submit']"
@@ -166,12 +172,12 @@ define ["./events", "./dom", "underscore"],
       # is an Ajax submission.
       return
 
-    dom.onDocument "submit", "form", defaultValidateAndSubmit
+    dom.onDocument "submit", TAPESTRY_CORE_FORM_SELECTOR, defaultValidateAndSubmit
 
     # On any click on a submit or image, update the containing form to indicate that the element
     # was responsible for the eventual submit; this is very important to Ajax updates, otherwise the
     # information about which control triggered the submit gets lost.
-    dom.onDocument "click", "input[type=submit], input[type=image]", ->
+    dom.onDocument "click", TAPESTRY_CORE_FORM_SELECTOR + " input[type=submit], " + TAPESTRY_CORE_FORM_SELECTOR + " input[type=image]", ->
       setSubmittingHidden (dom @element.form), this
       return
 
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
index 36477cb..f0cc268 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
@@ -117,6 +117,19 @@ public class Form implements ClientElement, FormValidationControl
      * @since 5.2.0
      */
     public static final String SUBMITTING_ELEMENT_ID = "t:submit";
+    
+    /**
+     * Name of the data attribute added to HTML forms generated by this component.
+     * @since 5.6.4
+     */
+    public static final String DATA_ATTRIBUTE = "data-generator";
+    
+    /**
+     * Name of the data attribute added to HTML forms generated by this component.
+     * @since 5.6.4
+     * @see #DATA_ATTRIBUTE
+     */
+    public static final String DATA_ATTRIBUTE_VALUE = "tapestry/core/form";
 
     public static final StreamPageContent STREAM_ACTIVE_PAGE_CONTENT = new StreamPageContent().withoutActivation();
 
@@ -370,7 +383,8 @@ public class Form implements ClientElement, FormValidationControl
                 "id", clientId,
                 "method", "post",
                 "action", actionURL,
-                "data-update-zone", zone);
+                "data-update-zone", zone,
+                DATA_ATTRIBUTE, DATA_ATTRIBUTE_VALUE);
 
         if (clientValidation != ClientValidation.NONE)
         {
diff --git a/tapestry-core/src/test/app1/ClientFormatDemo.tml b/tapestry-core/src/test/app1/ClientFormatDemo.tml
index 236bc26..097eb60 100644
--- a/tapestry-core/src/test/app1/ClientFormatDemo.tml
+++ b/tapestry-core/src/test/app1/ClientFormatDemo.tml
@@ -1,5 +1,11 @@
 <html t:type="border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
 
     <t:beaneditform object="this"/>
+    
+    <h2>Non-Tapestry form for testing TAP5-2669</h2>
+    
+    <form action="${linkToSamePage}">
+    	<input id="submitNonTapestryForm" type="submit"/>
+    </form>
 
 </html>
\ No newline at end of file
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ClientFormatDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ClientFormatDemo.java
index 0fb1471..85f5011 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ClientFormatDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ClientFormatDemo.java
@@ -14,14 +14,19 @@
 
 package org.apache.tapestry5.integration.app1.pages;
 
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.Link;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.beaneditor.Validate;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.PageRenderLinkSource;
 
 /**
  * Demonstrates client-side field format validation.
  */
 public class ClientFormatDemo
 {
+    
     @Property
     @Validate("required,min=1")
     private int quantity;
@@ -29,4 +34,15 @@ public class ClientFormatDemo
     @Property
     @Validate("required,min=0")
     private float amount;
+
+    @Inject
+    private ComponentResources resources;
+
+    @Inject
+    private PageRenderLinkSource pageRenderLinkSource;
+    
+    public Link getLinkToSamePage() {
+        return pageRenderLinkSource.createPageRenderLink(ClientFormatDemo.class);
+    }
+
 }