You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/07/16 18:09:58 UTC

[1/2] git commit: TAP5-2142: Handle exceptions during form validation

Updated Branches:
  refs/heads/master 75eaf6a5e -> a8ad6d265


TAP5-2142: Handle exceptions during form validation


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

Branch: refs/heads/master
Commit: c8bb56eeaf898fe7a96203d97c3e1d43fcf92a68
Parents: 75eaf6a
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Jul 15 17:21:47 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Jul 15 17:21:47 2013 -0700

----------------------------------------------------------------------
 .../META-INF/modules/t5/core/forms.coffee       | 51 ++++++++++++--------
 1 file changed, 32 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8bb56ee/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
----------------------------------------------------------------------
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 7c32fc2..e66fa09 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
@@ -99,31 +99,44 @@ define ["./events", "./dom", "./builder", "underscore"],
 
     defaultValidateAndSubmit = ->
 
-      if ((@attribute "data-validate") is "submit") and
-         (not @meta SKIP_VALIDATION)
+      where = -> "processing form submission"
 
-        @meta SKIP_VALIDATION, null
+      try
 
-        memo = error: false
+        if ((@attribute "data-validate") is "submit") and
+           (not @meta SKIP_VALIDATION)
 
-        for field in @find "[data-validation]"
-          field.trigger events.field.inputValidation, memo
+          @meta SKIP_VALIDATION, null
 
-        # Only do form validation if all individual field validation
-        # was successful.
-        unless memo.error
-          @trigger events.form.validate, memo
+          memo = error: false
 
-        if memo.error
-          clearSubmittingHidden this
-          # Cancel the original submit event when there's an error
-          return false
+          for field in @find "[data-validation]"
+            where = -> "triggering #{events.field.inputValidation} event on #{field.toString()}"
+            field.trigger events.field.inputValidation, memo
 
-      # Allow certain types of elements to do last-moment set up. Basically, this is for
-      # FormFragment, or similar, to make their hidden field enabled or disabled to match
-      # their UI's visible/hidden status. This is assumed to work or throw an exception; there
-      # is no memo.
-      @trigger events.form.prepareForSubmit
+          # Only do form validation if all individual field validation
+          # was successful.
+          unless memo.error
+            where = -> "trigging cross-form validation event"
+            @trigger events.form.validate, memo
+
+          if memo.error
+            clearSubmittingHidden this
+            # Cancel the original submit event when there's an error
+            return false
+
+        # Allow certain types of elements to do last-moment set up. Basically, this is for
+        # FormFragment, or similar, to make their hidden field enabled or disabled to match
+        # their UI's visible/hidden status. This is assumed to work or throw an exception; there
+        # is no memo.
+        where = -> "triggering #{events.form.prepareForSubmit} event (after validation)"
+
+        @trigger events.form.prepareForSubmit
+
+      catch error
+        console.error "Form validiation/submit error `#{error.toString()}', in form #{this.toString()}, #{where()}"
+        console.error error
+        return false
 
       # Otherwise, the event is good, there are no validation problems, let the normal processing commence.
       # Possibly, the document event handler provided by the t5/core/zone module will intercept form submission if this


[2/2] git commit: TAP5-2141: Ajax form submission should ignore fields with no name

Posted by hl...@apache.org.
TAP5-2141: Ajax form submission should ignore fields with no name


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

Branch: refs/heads/master
Commit: a8ad6d265d98bb379df64b941af3922406c06394
Parents: c8bb56e
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jul 16 09:09:52 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jul 16 09:09:52 2013 -0700

----------------------------------------------------------------------
 .../src/main/coffeescript/META-INF/modules/t5/core/forms.coffee | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a8ad6d26/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
----------------------------------------------------------------------
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 e66fa09..ef9cff1 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
@@ -82,6 +82,11 @@ define ["./events", "./dom", "./builder", "underscore"],
 
           name = field.element.name
 
+          # Many modern UIs create name-less elements on the fly (e.g., Backbone); these may be mixed
+          # in with normal elements managed by Tapestry but should be ignored (not sent to the server in a POST
+          # or Ajax update).
+          return if name is ""
+
           existing = result[name]
 
           if _.isArray existing


[2/2] git commit: TAP5-2141: Ajax form submission should ignore fields with no name

Posted by hl...@apache.org.
TAP5-2141: Ajax form submission should ignore fields with no name


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

Branch: refs/heads/master
Commit: a8ad6d265d98bb379df64b941af3922406c06394
Parents: c8bb56e
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jul 16 09:09:52 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jul 16 09:09:52 2013 -0700

----------------------------------------------------------------------
 .../src/main/coffeescript/META-INF/modules/t5/core/forms.coffee | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a8ad6d26/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
----------------------------------------------------------------------
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 e66fa09..ef9cff1 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
@@ -82,6 +82,11 @@ define ["./events", "./dom", "./builder", "underscore"],
 
           name = field.element.name
 
+          # Many modern UIs create name-less elements on the fly (e.g., Backbone); these may be mixed
+          # in with normal elements managed by Tapestry but should be ignored (not sent to the server in a POST
+          # or Ajax update).
+          return if name is ""
+
           existing = result[name]
 
           if _.isArray existing