Search code examples
jqueryformsvalidationexpressionengine

jQuery Validation Plugin with Input Arrays


I currently have a set of inputs that look like this:

<li class="required">
    <label>First Name</label>
    <input type="text" name="cf_member_address[row_id_52][col_id_19]" value="">
</li>
<li class="required">
    <label>Surname</label>
    <input type="text" name="cf_member_address[row_id_52][col_id_20]" value="">
</li>

and I'm using jQuery validate to validate the form before it submits. I'm trying to add custom messages to each item but i've hit a problem because of the arrays ([row_id_52])

Also, depending on the form that loads, depends on what row ID shows ([row_id_52]) - But the Col ID stays the same.

How can I declare:

  • An Array input field that has a dynamic number in it?

In my JS file? I'm currently doing it like this:

cf_member_first_name: "Please enter your First Name",

Any help would be appreciated!


Solution

  • jQuery validate will allow you to add validation rules using a selector other than the input name, so one way to avoid your issue of dynamic names is to assign a css id or class to each of your inputs and set up your validation rules per id or class. http://docs.jquery.com/Plugins/Validation/rules