jzaefferer/jquery-validation — Issue #275: IE7 bug in findByName if input has been added dynamically to dom
Author: nabster83
Created: 2011-12-06 17:02:21+00:00
State: open

Currently the findByName function looks as follows:

findByName: function( name ) {
// select by name and filter by form for performance over form.find("[name=...]")
var form = this.currentForm;
return $(document.getElementsByName(name)).map(function(index, element) {
return element.form == form && element.name == name && element || null;
});
}

This does not work correctly in IE7 in case you create the elements in the form dynamically via JavaScript API. It doesn't matter if you call $("#myForm").validate() before or after you add the fields dynamically to the dom. The problem seems to be that in IE7 the function

document.getElementsByName(name)

returns an empty array if the field has been added to the dom dynamically (although it actually exists!). so here is an easy example to show the issue live in IE7:

<html>
<body>

</body>
</html>

To make findByName compatible with IE7 the function should be rewritten or during runtime findByName should be replaced with some kind of findByNameIE7 function (latter could be done once when initializing the validation plugin).