| <?xml version="1.0"?> |
| <!DOCTYPE script |
| PUBLIC "-//Apache Software Foundation//Tapestry Script Specification 3.0//EN" |
| "http://jakarta.apache.org/tapestry/dtd/Script_3_0.dtd" |
| > |
| |
| |
| <!-- |
| Creates a script for validating that a field is required and/or has a minimum |
| field length. |
| |
| Input symbols: |
| field, form, validator: As normal for a validation script. |
| requiredMessage: Message to display if the field is required yet blank. |
| minimumLengthMessage: Message to display if the field length is too short. |
| urlFormatMessage: Message to display if the field value is not a valid URL. |
| urlRegexpProtocols: The regexp to check that the protocol is one of the allowed protocols. |
| urlDisallowedProtocolMessage: Message to display if the field value does not use an allowed protocol. |
| |
| --> |
| <script> |
| |
| <include-script resource-path="/org/apache/tapestry/valid/Validator.js" /> |
| |
| <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.UrlValidator" required="yes" /> |
| <input-symbol key="requiredMessage" class="java.lang.String" /> |
| <input-symbol key="minimumLengthMessage" class="java.lang.String" /> |
| <input-symbol key="urlFormatMessage" class="java.lang.String" /> |
| <input-symbol key="urlRegexpProtocols" class="java.lang.String" /> |
| <input-symbol key="urlDisallowedProtocolMessage" class="java.lang.String" /> |
| |
| <let key="function" unique="yes">validate_${field.name}</let> |
| |
| <body> |
| function ${function}() { |
| var field = document.${form.name}.${field.name}; |
| strValue = field.value.replace(/ /g,""); |
| field.value = strValue; |
| |
| <if expression="validator.required"> |
| if (strValue.length == 0) |
| return validator_invalid_field(field, "${requiredMessage}"); |
| </if> |
| |
| <if-not expression="validator.required"> |
| if (strValue.length == 0) |
| return true; |
| </if-not> |
| |
| <if expression="validator.minimumLength"> |
| if (strValue.length < ${validator.minimumLength}) |
| return validator_invalid_field(field, "${minimumLengthMessage}"); |
| </if> |
| |
| if(!regexpTestUrl(strValue)) |
| return validator_invalid_field(field, "${urlFormatMessage}"); |
| |
| <if expression="null != urlRegexpProtocols"> |
| var protoRegExp = ${urlRegexpProtocols}; |
| if(!protoRegExp.test(strValue)) |
| return validator_invalid_field(field, "${urlDisallowedProtocolMessage}"); |
| </if> |
| |
| return true; |
| } |
| </body> |
| |
| </script> |