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?

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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.

1 Comment

It has nothing to do with this. He's duplicating the name on every field and the plugin cannot work this way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.