Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm trying to validate a group of input arrays using jquery validator plugin. I'm having problems understanding how to pass another element into the validation.

My code so far:

$('#edit-fixtures').validate({
            rules: {
                "player_a[]": {
                    required: true,
                    uniqueMatch: function () {
                        return $(this).next('.player').val();
                    },
                },
                "player_b[]": {
                    required: true,
                    uniqueMatch: function () {
                        $(this).closest('.player').val();
                    },
                },
            }
        });

My input elements are a series of paired select boxes named player_a[] player_b[] There are about 40 pairs. Each pair should be unique and that's what i'll be validating.

I'm trying to pass the value of the nearest player_b to the changed player_a and vice versa.

I have a change method to validate on each change:

$(".player").change(function () {

            var check = $(this).valid();

            console.log("validation:", check);

        });

I'm still working on the validation method but cant seem to get the parameters to the method correctly.

Is there a way of doing this?

share|improve this question
    
Hi- yes it is, i;ve tried different approaches - neither mehtod really works - have changed the post to avoid confusion - thanks for pointing out. – Ray Jul 27 at 12:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.