0

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 is not unique.");

jQuery.validator.classRuleSettings.unique = {
    unique: true
};
$("#myform").validate();

$("#validate").click(function() {
    $("#myform").valid();
});

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

but If I will use different name than that will work,check http://jsfiddle.net/mysteryh/bgzBY/

So how to fix it?

Er.KT
  • 2,852
  • 1
  • 36
  • 70

2 Answers2

1

You cannot use the same name on more than one input field. There is no workaround for this requirement of the plugin. (It's how the plugin keeps track of the input elements.)

So how to fix it?

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

Sparky
  • 98,165
  • 25
  • 199
  • 285
-1

It has nothing to do with your names. Your script is not loading properly. Blocked loading mixed active content "http://ajax.microsoft.com/ajax/jquery.validate/1.8/jquery.validate.min.js" This is the error shown in console.

  • It has nothing to do with this. He's duplicating the `name` on every field and the plugin cannot work this way. – Sparky Jul 14 '15 at 14:37