I have a large number of dynamic cloned fields on a form. The fields are cloned groups.
Every time I add a clone I use a wildcard selector to allocate the rules to all the fields in the DOM.
$('[name^=myfieldname]').each(function() {
$(this).rules('add',{
required: true,
duplicatefield: true,
messages: {
required: "Myfieldname is required",
duplicatefield: "Myfieldname can not be duplicated"
}
});
});
The reason I do this is so that I can can a single function that I can call each time a clone is added or reindexed to ensure that all the fields in the DOM have the correct rules.
The result of this is that I will be allocating the rule multiple times to any pre-existing fields.
Is it incorrect to do this and does jQuery ignore the duplicated (added) rule or simply overwrite it?