jquery validation for unique with dynamic name of input -


this question has answer here:

i have used following jquery code

jquery.validator.addmethod("unique", function(value, element, params) {     var prefix = params;     var selector = jquery.validator.format("[name!='{0}'][name^='{1}'][unique='{1}']", element.name, prefix);     var matches = new array();     $(selector).each(function(index, item) {         if (value == $(item).val()) {             matches.push(item);         }     });      return matches.length == 0; }, "value not unique.");  jquery.validator.classrulesettings.unique = {     unique: true }; $("#myform").validate();  $("#validate").click(function() {     $("#myform").valid(); }); 

but due same input name not working properly, check here https://jsfiddle.net/bgzby/147/

but if use different name work,check http://jsfiddle.net/mysteryh/bgzby/

so how fix it?

you cannot use same name on more 1 input field. there no workaround requirement of plugin. (it's how plugin keeps track of input elements.)

so how fix it?

you must use unique name on every input. currency[1], currency[2], etc.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -