[ 
https://issues.apache.org/jira/browse/WW-2058?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12993024#comment-12993024
 ] 

Rafael Tupiná da Rocha commented on WW-2058:
--------------------------------------------

I used the solution from Frédéric Blanc and really solves the problem.

I needed to input a single line to update i variable since when we removeChild, 
the variable rows is automatically updated, so, with more errors some were not 
cleared.

function clearErrorMessagesXHTML(form) {

    // get field table
    var rows = form.getElementsByTagName("tr");
    if (rows == null){
        return;
    }

    for(var i = 0; i < rows.length; i++) {
        var r = rows[i];
        if (r.getAttribute("errorFor")) {
            rows[i].parentNode.removeChild(rows[i]);
            i--;
        }
    }
}

Tested with FF Firefox/3.6.13 and IE 7.0.5730.13

This is my first contribute so I don't know how to re-open this Issue.

> Client side validation in xhtml template and clearErrorMessages not working 
> in firefox with hidden fields
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: WW-2058
>                 URL: https://issues.apache.org/jira/browse/WW-2058
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Tags
>    Affects Versions: 2.0.11
>         Environment: Firefox and IE
>            Reporter: Max Pimm
>            Assignee: James Holmes
>            Priority: Minor
>             Fix For: 2.0.10, 2.1.0
>
>         Attachments: validation.js.patch, validation.js.patch
>
>
> The method clearErrorMessages in the xhtml client side validation template 
> (template/xhtml/validation.js) fails in firefox. This results in the error 
> messages being duplicated each time the form is submitted.
> The problem arises from the first three lines of code in the function:
>     var table = form.childNodes[1];
>     if( typeof table == "undefined" ) {
>         table = form.childNodes[0];
>     }
> This presumes that the first (or second) node of the form element is the 
> field table. However in firefox hidden fields within a form are moved in the 
> DOM to the top of its children. Thus wherever you put the hidden elements in 
> the form they appear in the DOM at the top. The same problem does not occur 
> in internet explorer or if no hidden fields are present. I have not tried 
> other browsers.
> I have replaced these three lines with the patch:
> // get field table
> var table;
> for (var i = 0; i < form.childNodes.length; i++){
>     if (form.childNodes[i].tagName != null && 
> form.childNodes[i].tagName.toLowerCase() == "table"){
>         table = form.childNodes[i];
>         break;
>     }
> }
> if (table == null){
>     return;
> }
> This solves the problem.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to