jzaefferer/jquery-validation — pull request #717 by imdhmd (2013-05-13 10:58:21+00:00)
Title: Allow validation across all inputs with same name

The following piece of code in jquery.validate.js, `elements()` function, explicitly ignores all elements with the same name (except for the first)

```javascript
...
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
return false;
}
...
```

IMO, we should rather apply the same validation rules for the elements with the same name. For which the modified piece of code would be:

```javascript
elements: function() {
var validator = this,
rulesCache = {};

// select all valid inputs inside the form (no submit or reset buttons)
return $(this.currentForm)
.find("input, select, textarea")
.not(":submit, :reset, :image, [disabled]")
.not( this.settings.ignore )
.filter(function() {
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this);
}

// select this element if this has the same name as one in cache (may be was dynamically added)
if ( this.name in rulesCache ) {
if ( !validator.objectLength($(this).rules()) ) {
$(this).rules('add', rulesCache[this.name]);
}
return true;
}

// select only the element with rules specified
if ( !validator.objectLength($(this).rules()) ) {
return false;
}

// Add rules to the cache
rulesCache[this.name] = $(this).rules();
return true;
});
},
```

What this also makes possible is, if inputs are dynamically added (in case where multi-inputs exist), the same validation would apply to those too.