Hi,

I've built a dynamic form that I want to validate using the JQuery
validate plugin. However I've hit a snag which I think is related to
how I'm naming form elements. I wondered whether anyone else has had
the same problem (or might have a solution!)

The dynamic aspects of the form are implemented with a little
microformat and a use of the JQuery clone() method. I have something
like:

<div class="repeated">
 <input type="text" name="ex:email" value=""/>
</div>

My code picks up on "repeated" form sections and adds some controls to
enable to the user to add/remove sections to the form. In this case,
the ability to add multiple email addresses. That bit works fine.

What I want to do is just add class="required email" to markup, and
have each individual email address be validated.

However at the moment the JQuery Validate plugin treats all of the
inputs as the same, i.e. if I click to add a second email address
field, with the first value being invalid and the second valid, then
the plugin seems to only ever be validating the original value.

I think this is because the plugin is using the field name attributes
as a key?

Yes, the obvious answer is to give all the controls unique names, but
I'd like to avoid that if possible as the field names are used
elsewhere and I'd rather avoid having to munge them to add/remove a
unique suffix (e.g. ex:email-1).

Any ideas?

Cheers,

L.
--
http://www.ldodds.com/blog

Reply via email to