tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/9] git commit: Use client-side JavaScript to decorate fields and present errors that same way as with client-side validation
Date Thu, 18 Oct 2012 00:17:10 GMT
Updated Branches:
  refs/heads/5.4-js-rewrite 0cbd81d4f -> 37fe751b8


Use client-side JavaScript to decorate fields and present errors that same way as with client-side
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/37fe751b
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/37fe751b
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/37fe751b

Branch: refs/heads/5.4-js-rewrite
Commit: 37fe751b8f79683698fe1899c894fe39ca562336
Parents: 3f442c5
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Wed Oct 17 17:16:46 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Wed Oct 17 17:16:46 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/fields.coffee            |    8 ++++----
 .../tapestry5/corelib/base/AbstractField.java      |    9 +++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/37fe751b/tapestry-core/src/main/coffeescript/META-INF/modules/core/fields.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/fields.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/fields.coffee
index 95c62c1..d2b12e2 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/fields.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/fields.coffee
@@ -35,7 +35,6 @@ define ["_", "core/events", "core/spi", "core/builder"],
     #
     # * field - element wrapper for the field
     findHelpBlock = (field) ->
-
       fieldId = field.getAttribute "id"
 
       # When the field has an id (the normal case!), search the body for
@@ -71,7 +70,6 @@ define ["_", "core/events", "core/spi", "core/builder"],
       return block
 
     createHelpBlock = (field) ->
-
       fieldId = ensureFieldId field
 
       # No containing group ... this is a problem, probably an old 5.3 application upgraded
to 5.4
@@ -90,6 +88,9 @@ define ["_", "core/events", "core/spi", "core/builder"],
 
       return block
 
+    showValidationError = (id, message) ->
+      spi.wrap(id).trigger events.field.showValidationError, { message }
+
     # Default registrations:
 
     spi.onDocument events.field.clearValidationError, ->
@@ -105,7 +106,6 @@ define ["_", "core/events", "core/spi", "core/builder"],
       return
 
     spi.onDocument events.field.showValidationError, (event, memo) ->
-
       block = exports.findHelpBlock this
 
       unless block
@@ -117,4 +117,4 @@ define ["_", "core/events", "core/spi", "core/builder"],
 
       group and group.addClass "error"
 
-    exports = {findHelpBlock, createHelpBlock}
\ No newline at end of file
+    exports = {findHelpBlock, createHelpBlock, showValidationError}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/37fe751b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
index 19824be..af7a3b0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
@@ -227,11 +227,20 @@ public abstract class AbstractField implements Field
 
     /**
      * Allows the validation decorator to write markup after the field has written all of
its markup.
+     * In addition, may invoke the <code>core/fields:showValidationError</code>
function to present
+     * the field's error (if it has one) to the user.
      */
     @AfterRender
     final void afterDecorator()
     {
         decorator.afterField(this);
+
+        String error = validationTracker.getError(this);
+
+        if (error != null)
+        {
+            javaScriptSupport.require("core/fields").invoke("showValidationError").with(assignedClientId,
error);
+        }
     }
 
     /**


Mime
View raw message