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
Post a Comment