Author: musachy
Date: Wed May 23 17:34:33 2007
New Revision: 541124

URL: http://svn.apache.org/viewvc?view=rev&rev=541124
Log:
WW-1903 Client side javascript validation has javascript errors when textfield 
labelposition is set to top

Modified:
    
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
    
struts/struts2/trunk/core/src/main/resources/template/xhtml/form-validate.ftl
    struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js
    
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
    
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-2.txt

Modified: 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js?view=diff&rev=541124&r1=541123&r2=541124
==============================================================================
--- 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js 
(original)
+++ 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js 
Wed May 23 17:34:33 2007
@@ -43,19 +43,18 @@
   }
 };
 
-
 StrutsUtils.firstElement  = function(parentNode, tagName) {
   var node = parentNode.firstChild;
   while(node && node.nodeType != 1){
     node = node.nextSibling;
   }
   if(tagName && node && node.tagName && node.tagName.toLowerCase() != 
tagName.toLowerCase()) {
-    node = dojo.dom.nextElement(node, tagName);
+    node = StrutsUtils.nextElement(node, tagName);
   }
   return node;  
 };
 
-StrutsUtils.nextElement = function(node, tagName){
+StrutsUtils.nextElement = function(node, tagName) {
   if(!node) { return null; }
   do {
     node = node.nextSibling;
@@ -63,6 +62,19 @@
 
   if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
     return StrutsUtils.nextElement(node, tagName);
+  }
+  return node;  
+}
+
+StrutsUtils.previousElement = function(node, tagName) {
+  if(!node) { return null; }
+  if(tagName) { tagName = tagName.toLowerCase(); }
+  do {
+    node = node.previousSibling;
+  } while(node && node.nodeType != 1);
+  
+  if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+    return StrutsUtils.previousElement(node, tagName);
   }
   return node;  
 }

Modified: 
struts/struts2/trunk/core/src/main/resources/template/xhtml/form-validate.ftl
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/xhtml/form-validate.ftl?view=diff&rev=541124&r1=541123&r2=541124
==============================================================================
--- 
struts/struts2/trunk/core/src/main/resources/template/xhtml/form-validate.ftl 
(original)
+++ 
struts/struts2/trunk/core/src/main/resources/template/xhtml/form-validate.ftl 
Wed May 23 17:34:33 2007
@@ -1,5 +1,6 @@
 <#if parameters.validate?default(false) == true>
        <script type="text/javascript" 
src="${base}/struts/xhtml/validation.js"></script>
+       <script type="text/javascript" src="${base}/struts/utils.js"></script>
        <#if parameters.onsubmit?exists>
                ${tag.addParameter('onsubmit', "${parameters.onsubmit}; return 
validateForm_${parameters.id}();")}
        <#else>

Modified: 
struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js?view=diff&rev=541124&r1=541123&r2=541124
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js 
(original)
+++ struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js 
Wed May 23 17:34:33 2007
@@ -40,13 +40,19 @@
     var elements = form.elements;
     for (var i = 0; i < elements.length; i++) {
         var e = elements[i];
-        var cells = e.parentNode.parentNode.cells;
-        if (cells && cells.length >= 2) {
-            var label = cells[0].getElementsByTagName("label")[0];
-            if (label) {
-                label.setAttribute("class", "label");
-                label.setAttribute("className", "label"); //ie hack cause ie 
does not support setAttribute
-            }
+        //parent could be a row, or a cell
+        var parent = e.parentNode.parentNode;
+         //if labelposition is 'top' the label is on the row above
+        if(parent.cells) {
+          var labelRow = parent.cells.length > 1 ? parent : 
StrutsUtils.previousElement(parent, "tr");
+          var cells = labelRow.cells;
+          if (cells && cells.length >= 1) {
+              var label = cells[0].getElementsByTagName("label")[0];
+              if (label) {
+                  label.setAttribute("class", "label");
+                  label.setAttribute("className", "label"); //ie hack cause ie 
does not support setAttribute
+              }
+          }
         }
     }
 
@@ -76,8 +82,10 @@
         tr.setAttribute("errorFor", e.id);;
         table.insertBefore(tr, row);
 
-        // updat the label too
-        var label = row.cells[0].getElementsByTagName("label")[0];
+        // update the label too
+        //if labelposition is 'top' the label is on the row above
+        var labelRow = row.cells.length > 1 ? row : 
StrutsUtils.previousElement(tr, "tr");
+        var label = labelRow.cells[0].getElementsByTagName("label")[0];
         label.setAttribute("class", "errorLabel");
         label.setAttribute("className", "errorLabel"); //ie hack cause ie does 
not support setAttribute
     } catch (e) {

Modified: 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt?view=diff&rev=541124&r1=541123&r2=541124
==============================================================================
--- 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
 (original)
+++ 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
 Wed May 23 17:34:33 2007
@@ -1,4 +1,5 @@
 <script type="text/javascript" src="/struts/xhtml/validation.js"></script>
+<script type="text/javascript" src="/struts/utils.js"></script>
 <form namespace="" id="myAction" name="myForm" onsubmit="submitMe(); return 
validateForm_myAction();" action="/myAction.action" method="POST" 
enctype="myEncType" title="mytitle" accept-charset="UTF-8">
 <table class="wwFormTable"> <tr>
     <td class="tdLabel"></td>

Modified: 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-2.txt
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-2.txt?view=diff&rev=541124&r1=541123&r2=541124
==============================================================================
--- 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-2.txt
 (original)
+++ 
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-2.txt
 Wed May 23 17:34:33 2007
@@ -1,4 +1,5 @@
 <script type="text/javascript" src="/struts/xhtml/validation.js"></script>
+<script type="text/javascript "src="/struts/utils.js"></script>
 <form namespace="" id="myAction" name="myForm" onsubmit="submitMe(); return 
validateForm_myAction();" action="/myAction.action" method="POST" 
enctype="myEncType" title="mytitle" accept-charset="UTF-8">
 <table class="wwFormTable"> <tr>
     <td class="tdLabel"></td>


Reply via email to