Commits

Anonymous committed 3e5faea

refactored css_xhtml theme to use validation parts from xhtml

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@1798573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 894043e

Comments (0)

Files changed (7)

File src/java/template/css_xhtml/controlheader.ftl

         ${parameters.label?html}:</label><#t/>
 </#if>
     <#lt/>
-
-<#if parameters.form?exists && parameters.form.validate?default(false) == true>
-	<#-- can't mutate the data model in freemarker -->
-    <#if parameters.onblur?exists>
-        ${tag.addParameter('onblur', "validate(this);${parameters.onblur}")}
-    <#else>
-        ${tag.addParameter('onblur', "validate(this);")}
-    </#if>
-</#if>

File src/java/template/css_xhtml/form-close.ftl

-</form>
+</form>
+<#include "/${parameters.templateDir}/xhtml/form-close-validate.ftl" />

File src/java/template/css_xhtml/form.ftl

-<#if parameters.validate?exists>
-<script src="${base}/webwork/validationClient.js"></script>
-<script src="${base}/dwr/interface/validator.js"></script>
-<script src="${base}/dwr/engine.js"></script>
-<script src="${base}/webwork/template/css_xhtml/validation.js"></script>
-</#if>
+<#include "/${parameters.templateDir}/xhtml/form-validate.ftl" />
 <#include "/${parameters.templateDir}/simple/form.ftl" />

File src/java/template/xhtml/form-close-validate.ftl

+<#if parameters.validate?exists>
+<script>
+    function validateForm_${parameters.id}() {
+        form = document.getElementById("${parameters.id}");
+        clearErrorRows(form.childNodes[1]);
+        clearErrorLabels(form);
+
+        var errors = false;
+    <#list parameters.tagNames as tagName>
+        <#list tag.getValidators("${tagName}") as validator>
+        // field name: ${validator.fieldName}
+        // validator name: ${validator.validatorType}
+        if (form.elements['${validator.fieldName}']) {
+            field = form.elements['${validator.fieldName}'];
+            var error = "${validator.defaultMessage}";
+            <#if validator.validatorType = "required">
+            if (field.value == "") {
+                addError(field, error);
+                errors = true;
+            }
+            <#elseif validator.validatorType = "requiredstring">
+            if (field.value != null && (field.value == "" || field.value.match("\W+"))) {
+                addError(field, error);
+                errors = true;
+            }
+            <#elseif validator.validatorType = "email">
+            if (field.value != null && field.value.match(/\\b(^(\\S+@).+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\..{2,2}))$)\\b/gi)) {
+                addError(field, error);
+                errors = true;
+            }
+            <#elseif validator.validatorType = "url">
+            if (field.value != null && field.value.match(/^(file|http):\\/\\/\\S+\\.(com|net|org|info|edu|mil|gov|biz|ws|us|tv|cc)$/i))) {
+                addError(field, error);
+                errors = true;
+            }
+            <#elseif validator.validatorType = "int">
+            if (field.value != null && (parseInt(field.value) < ${validator.min} || parseInt(field.value) > ${validator.max})) {
+                addError(field, error);
+                errors = true;
+            }
+            </#if>
+        }
+        </#list>
+    </#list>
+
+        return !errors;
+    }
+</script>
+</#if>

File src/java/template/xhtml/form-close.ftl

 </table>
 <#include "/${parameters.templateDir}/simple/form-close.ftl" />
-<#if parameters.validate?exists>
-<script>
-    function validateForm_${parameters.id}() {
-        form = document.getElementById("${parameters.id}");
-        clearErrorRows(form.childNodes[1]);
-        clearErrorLabels(form);
-
-        var errors = false;
-    <#list parameters.tagNames as tagName>
-        <#list tag.getValidators("${tagName}") as validator>
-        // field name: ${validator.fieldName}
-        // validator name: ${validator.validatorType}
-        if (form.elements['${validator.fieldName}']) {
-            field = form.elements['${validator.fieldName}'];
-            var error = "${validator.defaultMessage}";
-            <#if validator.validatorType = "required">
-            if (field.value == "") {
-                addError(field, error);
-                errors = true;
-            }
-            <#elseif validator.validatorType = "requiredstring">
-            if (field.value != null && (field.value == "" || field.value.match("\W+"))) {
-                addError(field, error);
-                errors = true;
-            }
-            <#elseif validator.validatorType = "email">
-            if (field.value != null && field.value.match(/\\b(^(\\S+@).+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\..{2,2}))$)\\b/gi)) {
-                addError(field, error);
-                errors = true;
-            }
-            <#elseif validator.validatorType = "url">
-            if (field.value != null && field.value.match(/^(file|http):\\/\\/\\S+\\.(com|net|org|info|edu|mil|gov|biz|ws|us|tv|cc)$/i))) {
-                addError(field, error);
-                errors = true;
-            }
-            <#elseif validator.validatorType = "int">
-            if (field.value != null && (parseInt(field.value) < ${validator.min} || parseInt(field.value) > ${validator.max})) {
-                addError(field, error);
-                errors = true;
-            }
-            </#if>
-        }
-        </#list>
-    </#list>
-
-        return !errors;
-    }
-</script>
-</#if>
+<#include "/${parameters.templateDir}/xhtml/form-close-validate.ftl" />

File src/java/template/xhtml/form-validate.ftl

+<#if parameters.validate?default(false) == true>
+<script src="${base}/webwork/template/xhtml/validation.js"></script>
+    <#if parameters.onsubmit?exists>
+        ${tag.addParameter('onsubmit', "return validateForm_${parameters.id}();${parameters.onblur}")}
+    <#else>
+        ${tag.addParameter('onsubmit', "return validateForm_${parameters.id}();")}
+    </#if>
+</#if>

File src/java/template/xhtml/form.ftl

-<#if parameters.validate?default(false) == true>
-<script src="${base}/webwork/template/xhtml/validation.js"></script>
-    <#if parameters.onsubmit?exists>
-        ${tag.addParameter('onsubmit', "return validateForm_${parameters.id}();${parameters.onblur}")}
-    <#else>
-        ${tag.addParameter('onsubmit', "return validateForm_${parameters.id}();")}
-    </#if>
-</#if>
+<#include "/${parameters.templateDir}/xhtml/form-validate.ftl" />
 <#include "/${parameters.templateDir}/simple/form.ftl" />
 <table class="wwFormTable">