| <?xml version="1.0"?> |
| <!-- |
| Copyright 2005 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 |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <!DOCTYPE script PUBLIC |
| "-//Apache Software Foundation//Tapestry Script Specification 3.0//EN" |
| "http://tapestry.apache.org/dtd/Script_3_0.dtd"> |
| <!-- |
| |
| Creates a script for validating that a field matches a required pattern. |
| |
| Input symbols: |
| field, form, validator: As normal for a validation script. |
| requiredMessage: Message to display if the field is required yet blank. |
| patternNotMatchedMessage: Message to display if the field does not fulfill the required pattern. |
| |
| --> |
| |
| <script> |
| <input-symbol key="field" class="org.apache.tapestry.valid.ValidField" required="yes"/> |
| <input-symbol key="form" class="org.apache.tapestry.IForm" required="yes"/> |
| <input-symbol key="validator" class="org.apache.tapestry.valid.PatternValidator" required="yes"/> |
| <input-symbol key="requiredMessage" class="java.lang.String"/> |
| <input-symbol key="patternNotMatchedMessage" class="java.lang.String" required="yes"/> |
| |
| <let key="function" unique="yes"> |
| validate_${field.name} |
| </let> |
| |
| <let key="pattern" unique="yes"> |
| pattern_${field.name} |
| </let> |
| |
| <body> |
| var ${pattern} = new RegExp("${validator.escapedPatternString}"); |
| |
| function ${function}(event) |
| { |
| var field = dojo.byId("${field.name}"); |
| <if expression="validator.required"> |
| if (field.value.length == 0) |
| { |
| Tapestry.invalid_field(field, "${requiredMessage}"); |
| dojo.event.browser.stopEvent(event); |
| return; |
| } |
| </if> |
| if (field.value.length > 0 && !${pattern}.test(field.value)) { |
| Tapestry.invalid_field(field, "${patternNotMatchedMessage}"); |
| dojo.event.browser.stopEvent(event); |
| } |
| } |
| </body> |
| |
| <initialization> |
| Tapestry.onsubmit('${form.name}', ${function}); |
| </initialization> |
| |
| </script> |