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 2012/12/27 00:00:24 UTC
git commit: Add a special case for validation with the Palette
component - the
Updated Branches:
refs/heads/master 5e624ae65 -> 1e9196cb5
Add a special case for validation with the Palette component
- the <select> field's value is all option values (selected or otherwise)
- triggered by the data-value-mode attribute set to "options"
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/1e9196cb
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/1e9196cb
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/1e9196cb
Branch: refs/heads/master
Commit: 1e9196cb5a25b593c71abae801b883c912b18644
Parents: 5e624ae
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed Dec 26 15:00:14 2012 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed Dec 26 15:00:14 2012 -0800
----------------------------------------------------------------------
.../META-INF/modules/t5/core/events.coffee | 11 +++++++++--
.../META-INF/modules/t5/core/fields.coffee | 13 ++++++++++++-
.../tapestry5/corelib/components/Palette.tml | 5 ++++-
3 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1e9196cb/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee
index cc2a9bc..c9d7337 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee
@@ -55,10 +55,17 @@ define
field:
# Perform the optionality check. The event memo includes a `value` property. If the field is required
- # but the value is blank, then a validation error should be presented (as described above).
+ # but the value is blank, then a validation error should be presented (as described above). The `value`
+ # property of the memo is as described for the `translate` event.
optional: "t5:field:optional"
- # Trigged by the field if there is a field value. The event memo includes the value as the `value` property.
+ # Trigged by the field if there is a field value (a non-empty string, or a non-empty array in the case
+ # of a select element). The event memo includes the field's value as the `value` property.
+ # For text fields, the value is the text inside the field. For select elements, it is an array of the values
+ # of selected options. If the element has the attribute `data-value-mode` set to 'options', then the
+ # value will be the array of all options (selected or not; this is provided for the core/Palette Tapestry
+ # component).
+ #
# An event handler may update the event, setting the `translated` property to an alternate formatting, or
# alternate representation (e.g., `Date`, or a number) for the input value. If the input can not be translated,
# then a validation error should be presented (as described above).
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1e9196cb/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee
index 795900e..a17c631 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/fields.coffee
@@ -87,9 +87,13 @@ define ["_", "./events", "./dom", "./builder", "./utils", "./forms"],
return block
+ # This may be removed soon:
showValidationError = (id, message) ->
dom.wrap(id).trigger events.field.showValidationError, { message }
+ collectOptionValues = (wrapper) ->
+ _.pluck wrapper.element.options, "value"
+
# Default registrations:
dom.onDocument events.field.inputValidation, (event, formMemo) ->
@@ -102,7 +106,13 @@ define ["_", "./events", "./dom", "./builder", "./utils", "./forms"],
failure = false
- memo = value: this.value()
+ fieldValue =
+ if (this.attribute "data-value-mode") is "options"
+ collectOptionValues this
+ else
+ this.value()
+
+ memo = value: fieldValue
postEventTrigger = =>
if memo.error
@@ -110,6 +120,7 @@ define ["_", "./events", "./dom", "./builder", "./utils", "./forms"],
failure = true
if _.isString memo.error
+
this.trigger events.field.showValidationError, { message: memo.error }
this.trigger events.field.optional, memo
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1e9196cb/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Palette.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Palette.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Palette.tml
index d438426..7512185 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Palette.tml
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Palette.tml
@@ -43,7 +43,10 @@
<div class="t-palette-title">
<t:delegate to="selectedLabel"/>
</div>
- <select t:type="any" t:id="selected" id="${clientId}" multiple="multiple" size="${size}" disabled="${disabledValue}" t:mixins="rendernotification">
+ <t:remove>
+ data-value=mode="options" is a bit of hack to inform the client side that the value for the field is all options, selected or not.
+ </t:remove>
+ <select t:type="any" t:id="selected" id="${clientId}" multiple="multiple" size="${size}" disabled="${disabledValue}" data-value-mode="options" t:mixins="rendernotification">
<t:remove>Starts empty, populated on the client side.</t:remove>
</select>
</div>