-1

I am using the following jQuery validation plugin:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

I am trying to validate a nested array "tax_percents[]" which is inside another array. It only validates the first value in the array. The odd part is, for the second field in the array it kind of validates it and gives an error message in field 1.

Here is a live demo showing the error:

http://blastohosting.com/jquery_validate_array_error/

I have the following document:

<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script src="jquery.validate.js"></script>
</head>

<body>
<form action="" method="post" id="theForm">
Location 1 Tax 1:
<input type="text" name="locations[1][tax_percents][]" />
<br /><br />

Location 1 Tax 1:
<input type="text" name="locations[1][tax_percents][]" />
<br /><br />
Location 2 Tax 2:
<input type="text" name="locations[2][tax_percents][]" />
<br /><br />

Location 2 Tax 2:
<input type="text" name="locations[2][tax_percents][]" />

<input type="submit" />
</form>

<script>
    $("#theForm").validate({
        rules: 
        {
            "locations[1][tax_percents][]":
            {
                number: true
            },
            "locations[2][tax_percents][]":
            {
                number: true
            }
        }
    });
</script>
</body>
</html>

What am I doing incorrectly?

3
  • You said: "The odd part is, for the second field in the array it kind of validates it and gives an error message in field 1." And I see the two inputs duplicated with the same name. That could be a reason... Commented Feb 4, 2014 at 16:44
  • Probably, this answer will help you a litte bit more. stackoverflow.com/questions/1978664/… Commented Feb 4, 2014 at 16:52
  • I understand that I am allowed to have inputs with the same name. (Thats what I need on the server side, but it makes client side validation tricky) Commented Feb 4, 2014 at 17:02

1 Answer 1

0

The library doesn't support this functionality of having things named the same and validate each input.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.