tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject tapestry-5 git commit: TAP5-2480: HTML5 vs. Form Fragment, in Chrome
Date Mon, 01 Jun 2015 17:56:19 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 450b36abb -> 6e1ebb30c


TAP5-2480: HTML5 vs. Form Fragment, in Chrome

This changes FormFragment to disable all input fields inside the fragment when it is hidden
(including if it is hidden
on initial render). When the fragment is shown, it finds the hidden fields and enables them.


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/6e1ebb30
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/6e1ebb30
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/6e1ebb30

Branch: refs/heads/master
Commit: 6e1ebb30ce572efde8cb6ebc83f5ca46f80a04e7
Parents: 450b36a
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Jun 1 10:56:08 2015 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Jun 1 10:56:08 2015 -0700

----------------------------------------------------------------------
 .../modules/t5/core/form-fragment.coffee        | 43 ++++++++++++++------
 .../corelib/components/FormFragment.java        | 18 ++++----
 2 files changed, 39 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6e1ebb30/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee
b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee
index 24c8fd8..f4b92ea 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/form-fragment.coffee
@@ -1,5 +1,3 @@
-# Copyright 2012, 2013 The Apache Software Foundation
-#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
@@ -20,21 +18,31 @@ define ["underscore", "./dom", "./events", "./forms"],
 
     SELECTOR = "[data-component-type='core/FormFragment']"
 
-    # When any form fires the prepareForSubmit event, check to see if
-    # any form fragments are contained within, and give them a chance
-    # to enabled/disable their hidden field.
-    dom.onDocument events.form.prepareForSubmit, "form", (event) ->
+    REENABLE = "data-re-enable-when-fragment-visible"
+
+    disableInputFields = (fragment) ->
+
+      # This is an example of where the t5/core/dom abstraction label is problematic,
+      # as this is very inefficient vs. the native jQuery approach.
+      for field in fragment.find "input:not(:disabled)"
+        field.attr "disabled", true
+        field.attr REENABLE, true
+
+    renableInputFields = (fragment) ->
 
-      fragments = @find SELECTOR
+      for field in fragment.find "input[#{REENABLE}]"
+        field.attr "disabled", null
+        field.attr REENABLE, null
 
-      _.each fragments, (frag) ->
+    updateFields = (fragment, makeVisible) ->
 
-        fragmentId = frag.attr "id"
+      # This is a server side option that says the content of the fragment should always
be submitted,
+      # even if the fragment is not currently visible.
+      return if fragment.attr "data-always-submit"
 
-        hidden = frag.findFirst "input[type=hidden][data-for-fragment='#{fragmentId}']"
+      f = if makeVisible then renableInputFields else disableInputFields
 
-        # If found (e.g., not alwaysSubmit), then enable/disable the field.
-        hidden && hidden.attr "disabled", not frag.deepVisible()
+      f fragment
 
     # Again, a DOM event to make the FormFragment visible or invisible; this is useful
     # because of the didShow/didHide events ... but we're really just seeing the evolution
@@ -45,10 +53,19 @@ define ["underscore", "./dom", "./events", "./forms"],
 
         this[if makeVisible then "show" else "hide"]()
 
+        updateFields this, makeVisible
+
         @trigger events.element[if makeVisible then "didShow" else "didHide"]
 
         return false
 
+    # When a FormFragment is initially rendered as hidden, then we need to do some
+    # book-keeping on the client side.
+    hide = (id) ->
+      field = dom(id)
+
+      updateFields field, false
+
     # Initializes a trigger for a FormFragment
     #
     # * spec.triggerId - id of checkbox or radio button
@@ -72,4 +89,4 @@ define ["underscore", "./dom", "./events", "./forms"],
         trigger.on "click", update
 
     # Module exports:
-    { linkTrigger }
+    { linkTrigger, hide }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6e1ebb30/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
index aadfa00..ad6ea47 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
@@ -164,11 +164,20 @@ public class FormFragment implements ClientElement
                 "id", clientId,
                 "data-component-type", "core/FormFragment");
 
+        if (alwaysSubmit) {
+            element.attribute("data-always-submit", "true");
+        }
+
         resources.renderInformalParameters(writer);
 
         if (!visible)
         {
             element.attribute("style", "display: none;");
+
+            if (!alwaysSubmit)
+            {
+                javascriptSupport.require("t5/core/form-fragment").invoke("hide").with(clientId);
+            }
         }
 
         componentActions = new ComponentActionSink(logger, clientDataEncoder);
@@ -222,17 +231,8 @@ public class FormFragment implements ClientElement
 
                 "name", Form.FORM_DATA,
 
-
                 "value", componentActions.getClientData());
 
-        if (!alwaysSubmit)
-        {
-            // Make it possible for the FormFragment to locate the hidden field, even if
-            // FormFragments get nested in some complex way.  When the always submit option
-            // is enabled, there's no need for the hidden field to be locatable.
-            hidden.attributes("data-for-fragment", clientId);
-        }
-
         writer.end(); // div
 
 


Mime
View raw message