Commits

Anonymous committed bd24f9a

WW-1433
- Client-side js validation doesn't work (see QuizClient example)
- WW-1416 fixes introduced dojo dependency into 'xhtml' theme through validation.js under the xhtml directory. Dojo dependency should be removed as xhtml should not need dojo, 'ajax' theme does.

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

Comments (0)

Files changed (1)

src/java/template/xhtml/validation.js

 /*
  * <!-- START SNIPPET: ajaxValidation -->
  */
+ 
+/*
+ * This function is copied over from Dojo, such that 'xhtml' theme doesn't depends
+ * on Dojo.
+ */
+function previousElement(/* Node */ node, /*string? */ tagName) { 
+	//	summary:
+	//		returns the previous sibling element matching tagName
+	if(!node) { return null; }
+	if(tagName) { tagName = tagName.toLowerCase(); }
+	do {
+		node = node.previousSibling;
+	} while(node && node.nodeType != 1 /* ELEMENT_NODE */);
 
+	if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+		return previousElement(node, tagName);
+	}
+	return node;	//	Element
+} 
+ 
 function clearErrorMessages(form) {
     var table = form.childNodes[1];
     if( typeof table == "undefined" ) {
     for (var i = 0; i < rowsToDelete.length; i++) {
         var r = rowsToDelete[i];
         table.deleteRow(r.rowIndex);
-        //table.removeChild(rowsToDelete[i]); 
     }
 }
 
         if (cells && cells.length >= 2) {  // when labelposition='left'
         	label = cells[0].getElementsByTagName("label")[0];
         }
-        else { // when labelposition='top'
+        else if (cells && cells.length >=1) { // when labelposition='top'
         	if (e.parentNode.parentNode) {
-				if (dojo.dom.prevElement(e.parentNode.parentNode)) {       		
-        			label = dojo.dom.prevElement(e.parentNode.parentNode).getElementsByTagName("label")[0];
+        		if (previousElement(e.parentNode.parentNode)) {      
+        			label = previousElement(e.parentNode.parentNode).getElementsByTagName("label")[0];
         		}
         	}
         }	
         	 td.colSpan = 2;
         }
         else {
-        	if (dojo.dom.prevElement(row)) { // when labelposition='top'
-        		label = dojo.dom.prevElement(row).getElementsByTagName("label")[0];
+        	if (previousElement(row)) { // when labelposition='top'
+        		label = previousElement(row).getElementsByTagName("label")[0];
         	}
         }