Author: wesw
Date: Fri Mar  6 16:27:58 2009
New Revision: 750961

URL: http://svn.apache.org/viewvc?rev=750961&view=rev
Log:
closer to having a working jquery-ified jqueryUtils.js and validation.js

Modified:
    
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/org/apache/struts2/static/jqueryUtils.js
    
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form-close-validate.ftl
    
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form.ftl
    
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/validation.js

Modified: 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/org/apache/struts2/static/jqueryUtils.js
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/org/apache/struts2/static/jqueryUtils.js?rev=750961&r1=750960&r2=750961&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/org/apache/struts2/static/jqueryUtils.js
 (original)
+++ 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/org/apache/struts2/static/jqueryUtils.js
 Fri Mar  6 16:27:58 2009
@@ -38,55 +38,18 @@
 // shows validation errors using functions from xhtml/validation.js
 // or css_xhtml/validation.js
 StrutsJQueryUtils.showValidationErrors = function(form, errors) {
-  StrutsJQueryUtils.clearValidationErrors(form, errors);
+  StrutsJQueryUtils.clearValidationErrors(form);
     
   if(errors.fieldErrors) {
     for(var fieldName in errors.fieldErrors) {
       for(var i = 0; i < errors.fieldErrors[fieldName].length; i++) {
-        addErrorJquery( $("#"+form+" > input[name="+fieldName+"]"), 
+        addErrorJquery( $("input[name=\""+fieldName+"\"]").attr("id"),
                  errors.fieldErrors[fieldName][i]);
       }
     }
   }
 };
 
-/*
-StrutsJQueryUtils.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 = StrutsJQueryUtils.nextElement(node, tagName);
-  }
-  return node;  
-};
-
-StrutsJQueryUtils.nextElement = function(node, tagName) {
-  if(!node) { return null; }
-  do {
-    node = node.nextSibling;
-  } while(node && node.nodeType != 1);
-
-  if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
-    return StrutsJQueryUtils.nextElement(node, tagName);
-  }
-  return node;  
-};
-
-StrutsJQueryUtils.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 StrutsJQueryUtils.previousElement(node, tagName);
-  }
-  return node;  
-};
-*/
 StrutsJQueryUtils.addOnLoad = function(func) {
   $().ready(func);
 };

Modified: 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form-close-validate.ftl
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form-close-validate.ftl?rev=750961&r1=750960&r2=750961&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form-close-validate.ftl
 (original)
+++ 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form-close-validate.ftl
 Fri Mar  6 16:27:58 2009
@@ -73,6 +73,7 @@
             });
             $.get("${parameters.action}", formData, 
${parameters.ajaxResultHandler} );
 <#else>
+            var form = document.getElementById("${parameters.id}");
             form.submit();
 </#if>
         }

Modified: 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form.ftl
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form.ftl?rev=750961&r1=750960&r2=750961&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form.ftl
 (original)
+++ 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/form.ftl
 Fri Mar  6 16:27:58 2009
@@ -23,7 +23,7 @@
 <#include "/${parameters.templateDir}/jquery/form-validate.ftl" />
 <#include "/${parameters.templateDir}/simple/form-common.ftl" />
 <#if parameters.validate?default(true) == true>
-  
onreset="${parameters.onreset?default('clearErrorMessages(this);clearErrorLabels(this);')}"
+  
onreset="${parameters.onreset?default('clearErrorMessages(\'${parameters.id}\');clearErrorLabels(\'${parameters.id}\');')}"
 <#else>
   <#if parameters.onreset??>
   onreset="${parameters.onreset?html}"

Modified: 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/validation.js
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/validation.js?rev=750961&r1=750960&r2=750961&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/validation.js
 (original)
+++ 
struts/sandbox/trunk/struts2-jquery-plugin/src/main/resources/template/jquery/validation.js
 Fri Mar  6 16:27:58 2009
@@ -25,7 +25,7 @@
 
 function clearErrorMessagesJquery(form) {
 
-    $("#"+form+" > tr[errorFor!=null]").remove();
+    $("#"+form+" > tr[errorFor]").remove();
 }
 
 function clearErrorLabels(form) {
@@ -33,7 +33,7 @@
 }
 
 function clearErrorLabelsJquery(form) {
-    $("#"+form+"> .errorLabel").addClass("label").removeClass("errorLabel");
+    $("#"+form+"> .errorLabel").removeClass("errorLabel");
 }
 
 function addError(e, errorText) {
@@ -41,47 +41,13 @@
 }
 
 function addErrorJquery(e, errorText) {
-    var parentRow = $(e).parent("tr").get(0);
-    $(parentRow).before(
-        $("<tr></tr>").attr("errorFor", e).html(
-            $("<td></td>").attr("colspan", "2").html(
-                $("<span></span>").addClass("errorMessage").html(errorText)
-                    )
+
+    $("#"+e).closest("tr").before(
+      $(document.createElement("tr")).attr({errorFor:e}).html(
+        $(document.createElement("td")).attr({colspan:2}).html(
+          
$(document.createElement("span")).addClass("errorMessage").html(errorText)
                 )
-            );
+            )
+        );
     $("label[for="+ e +"]").addClass('errorLabel');
-    /*
-    try {
-        var row = (e.type ? e : e[0]);
-        while(row.nodeName.toUpperCase() != "TR") {
-            row = row.parentNode;
-        }
-        var table = row.parentNode;
-        var error = document.createTextNode(errorText);
-        var tr = document.createElement("tr");
-        var td = document.createElement("td");
-        var span = document.createElement("span");
-        td.align = "center";
-        td.valign = "top";
-        td.colSpan = 2;
-        span.setAttribute("class", "errorMessage");
-        span.setAttribute("className", "errorMessage"); //ie hack cause ie 
does not support setAttribute
-        span.appendChild(error);
-        td.appendChild(span);
-        tr.appendChild(td);
-        tr.setAttribute("errorFor", e.id);
-        table.insertBefore(tr, row);
-
-        // 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];
-        if (label) {
-            label.setAttribute("class", "errorLabel");
-            label.setAttribute("className", "errorLabel"); //ie hack cause ie 
does not support setAttribute
-        }
-    } catch (e) {
-        alert(e);
-    }
-    */
 }


Reply via email to