WW-3952 Adds client side validation support

Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9eec07b3
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9eec07b3
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9eec07b3

Branch: refs/heads/master
Commit: 9eec07b310b4ac9e99342cfd632293acd2a45d8b
Parents: eb4fcb4
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Sat Apr 22 17:40:40 2017 +0200
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Sat Apr 22 17:40:40 2017 +0200

----------------------------------------------------------------------
 .../template/xhtml/form-close-validate.ftl      | 28 ++++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/9eec07b3/core/src/main/resources/template/xhtml/form-close-validate.ftl
----------------------------------------------------------------------
diff --git a/core/src/main/resources/template/xhtml/form-close-validate.ftl 
b/core/src/main/resources/template/xhtml/form-close-validate.ftl
index e8dd991..3ffc3bf 100644
--- a/core/src/main/resources/template/xhtml/form-close-validate.ftl
+++ b/core/src/main/resources/template/xhtml/form-close-validate.ftl
@@ -41,9 +41,9 @@ END SNIPPET: supported-validators
         -->
         var getFieldValue = function(field) {
             var type = field.type ? field.type : field[0].type;
-            if (type == 'select-one' || type == 'select-multiple') {
-                return (field.selectedIndex == -1 ? "" : 
field.options[field.selectedIndex].value);
-            } else if (type == 'checkbox' || type == 'radio') {
+            if (type === 'select-one' || type === 'select-multiple') {
+                return (field.selectedIndex === -1 ? "" : 
field.options[field.selectedIndex].value);
+            } else if (type === 'checkbox' || type === 'radio') {
                 if (!field.length) {
                     field = [field];
                 }
@@ -79,25 +79,25 @@ END SNIPPET: supported-validators
             var fieldValue = getFieldValue(field);
             
             <#if validator.validatorType = "required">
-            if (fieldValue == "") {
+            if (fieldValue === "") {
                 addError(field, error);
                 errors = true;
                 <#if validator.shortCircuit>continueValidation = false;</#if>
             }
             <#elseif validator.validatorType = "requiredstring">
-            if (continueValidation && fieldValue != null && (fieldValue == "" 
|| fieldValue.replace(/^\s+|\s+$/g,"").length == 0)) {
+            if (continueValidation && fieldValue !== null && (fieldValue === 
"" || fieldValue.replace(/^\s+|\s+$/g,"").length === 0)) {
                 addError(field, error);
                 errors = true;
                 <#if validator.shortCircuit>continueValidation = false;</#if>
             }
             <#elseif validator.validatorType = "stringlength">
-            if (continueValidation && fieldValue != null) {
+            if (continueValidation && fieldValue !== null) {
                 var value = fieldValue;
                 <#if validator.trim>
                     //trim field value
-                    while (value.substring(0,1) == ' ')
+                    while (value.substring(0,1) === ' ')
                         value = value.substring(1, value.length);
-                    while (value.substring(value.length-1, value.length) == ' 
')
+                    while (value.substring(value.length-1, value.length) === ' 
')
                         value = value.substring(0, value.length-1);
                 </#if>
                 if ((${validator.minLength?c} > -1 && value.length < 
${validator.minLength?c}) ||
@@ -108,25 +108,25 @@ END SNIPPET: supported-validators
                 }
             }
             <#elseif validator.validatorType = "regex">
-            if (continueValidation && fieldValue != null && 
!fieldValue.match("${validator.regex?js_string}")) {
+            if (continueValidation && fieldValue !== null && 
!fieldValue.match("${validator.regex?js_string}")) {
                 addError(field, error);
                 errors = true;
                 <#if validator.shortCircuit>continueValidation = false;</#if>
             }
-            <#elseif validator.validatorType = "email">
-            if (continueValidation && fieldValue != null && fieldValue.length 
> 0 && fieldValue.match(/${validator.regex}/i)==null) {
+            <#elseif validator.validatorType = "email" || 
validator.validatorType = "creditcard">
+            if (continueValidation && fieldValue !== null && fieldValue.length 
> 0 && fieldValue.match(/${validator.regex}/i) === null) {
                 addError(field, error);
                 errors = true;
                 <#if validator.shortCircuit>continueValidation = false;</#if>
             }
             <#elseif validator.validatorType = "url">
-            if (continueValidation && fieldValue != null && fieldValue.length 
> 0 && fieldValue.match(/${validator.urlRegex}/i)==null) {
+            if (continueValidation && fieldValue !== null && fieldValue.length 
> 0 && fieldValue.match(/${validator.urlRegex}/i) === null) {
                 addError(field, error);
                 errors = true;
                 <#if validator.shortCircuit>continueValidation = false;</#if>
             }
             <#elseif validator.validatorType = "int" || 
validator.validatorType = "short">
-            if (continueValidation && fieldValue != null) {
+            if (continueValidation && fieldValue !== null) {
                 if (<#if validator.min??>parseInt(fieldValue) <
                      ${validator.min?c}<#else>false</#if> ||
                         <#if validator.max??>parseInt(fieldValue) >
@@ -137,7 +137,7 @@ END SNIPPET: supported-validators
                 }
             }
             <#elseif validator.validatorType = "double">
-            if (continueValidation && fieldValue != null) {
+            if (continueValidation && fieldValue !== null) {
                 var value = parseFloat(fieldValue);
                 if (<#if validator.minInclusive??>value < 
${validator.minInclusive?c}<#else>false</#if> ||
                         <#if validator.maxInclusive??>value > 
${validator.maxInclusive?c}<#else>false</#if> ||

Reply via email to