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

Chris Muench
  • 17,444
  • 70
  • 209
  • 362
  • 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... – celerno Feb 04 '14 at 16:44
  • Probably, this answer will help you a litte bit more. http://stackoverflow.com/questions/1978664/is-it-possible-to-have-double-nested-input-tag-arrays-in-html – celerno Feb 04 '14 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) – Chris Muench Feb 04 '14 at 17:02

1 Answers1

0

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

Chris Muench
  • 17,444
  • 70
  • 209
  • 362