posabsolute / jQuery-Validation-Engine

jQuery form validation plugin
http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
2.57k stars 1.2k forks source link

Multiple TextBoxes Not Equal #910

Closed ThomasAcker closed 5 years ago

ThomasAcker commented 8 years ago

I am trying to extend this and have added a notEqualToGroup for text boxes. Not sure where I am going wrong. I found this code online and trying to modify it.

"notEqualToGroup": { "func": function (value, element, options) { var elems = $(element).find(options[1]); // get all the elements passed here with the same class var valueToCompare = value; // the value of the current element var matchesFound = 0; // count

                    // loop each element and compare its value with the current value and increase the count every time we find one
                    jQuery.each(elems, function () {
                        thisVal = $(this).val();
                        if (thisVal == valueToCompare) {
                            matchesFound++;
                            return this.optional(element) || notEqual;
                        }
                    });

                    // count should be either 0 or 1 max
                    if (matchesFound <= 1) {
                        return false;
                    }

                },
                "alertText": "* Please enter a Unique Value."
            },