Hi Jörn

Firstly, the form I have to work with is not of my creation and is
somewhat flawed!

I agree, your first example would be invalid if the forms were on the
same page. If they were on separate pages the IDs are not invalid.

However my example is a form that collects a number of instances of
the same type of data. When the instance limit is reached, the user
progresses to the next stage. Take registering multiple delegates to a
conference as an example; you need to register the same type of detail
for each delegate. (Ideally a delegate number would be saved to the
database therefore negating this whole issue, but this is not the case
here and it does serve to illustrate a problematic area).

Example:
<!-- page 1 -->
<form id="frm">
<input id="e1" name="e1_1" />
<input id="e2" name="e2_1" />
</form>

<!-- page 2 -->
<form id="frm">
<input id="e1" name="e1_2" />
<input id="e2" name="e2_2" />
</form>

<!-- page n -->
<form id="frm">
<input id="e1" name="e1_n" />
<input id="e2" name="e2_n" />
</form>

Where e1_1, e1_2 and e1_n refer to the same type of content, which can
be referenced with the ID, and likewise for e2 etc.

By refering to the name of the field for validation you are tightly
coupling your script to the name therefore a script would have to be
created for each iteration.

Your second example would pose a problem if you wanted to show
validation errors based on, for example, an individual checkbox chosen
within a given group (unless I am very much mistaken).

Furthermore, whether using a JavaScript framework or not, it is more
robust refering to an element by it's ID (i.e. getElementById or $
("#ID")). Infact, you do in certain cases use the ID as reference
(e.g. when refering to dependencies, for example "#fieldID:checked").

If you could build in a solution that also allows a developer to
decide whether to refer to name or ID when creating rules/messages,
you will be able to serve everyones needs. I hope it isn't to
complicated to achieve :-/

Thanks,
Simon


On Jun 25, 7:53 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]>
wrote:
> Let just get this straight, I consider this invalid and useless html:
>
> <form>
> <input id="e1" name="e1_1" />
> <input id="e2" name="e1_2" />
> </form>
> <form>
> <input id="e1" name="e2_1" />
> <input id="e2" name="e2_2" />
> </form>
>
> While this is valid and useful, and works fine with the validation plugin:
>
> <form>
> <input id="e1_1" name="e1" />
> <input id="e1_2" name="e2" />
> </form>
> <form>
> <input id="e2_1" name="e1" />
> <input id="e2_2" name="e2" />
> </form>
>
> So either of us is missing something, which we need to clear up at first.
>
> Let me know what you think, I sure hope to find a solution to this
> that works for both of us.
>
> Jörn
>
> On Wed, Jun 25, 2008 at 12:58 PM,SimonWhatley<[EMAIL PROTECTED]> wrote:
>
> > Hi Jörn,
>
> > IDs are unique to the page rather than across forms, names do not have
> > to be. The forms I refer to are not on the same page, but on a new
> > instance of the page when a user clicks the submit button. The rule
> > should/could therefore apply to the ID and not the name, since the
> > name can be dynamic.
>
> > There are two ways I can get around this. Use a server-side scripting
> > language to dynamically output the correct JavaScript and therefore
> > rules and messages or hack the validation plugin. It's not great doing
> > either.
>
> > I will try looking at the plugin option since it is a more sensible
> > approach. I would suggest that the plugin support element IDs as this
> > is the only way you can guarantee a rule be applied to a specific
> > element (assuming people adhere to the uniqueness of an ID). If you
> > can somehow allow the plugin to be based on either name or ID, to be
> > specified by the developer and defaulting to name, it will allow for
> > backwards compatibility.
>
> > If I get something working with element.id, I'll send the code over to
> > you.
>
> > Thanks,
> >Simon
>
> > On Jun 25, 11:24 am, "Jörn Zaefferer" <[EMAIL PROTECTED]>
> > wrote:
> >> Repeating the same IDs across forms won't work, IDs have to be unique.
> >> That is why the plugin relies on names, as those have to be unique
> >> (from the plugin point of view) only within their form.
>
> >> You can try to hack the plugin, replacing all element.name snippets
> >> with element.id, but I won't support that.
>
> >> Jörn
>
> >> On Wed, Jun 25, 2008 at 12:10 PM,SimonWhatley<[EMAIL PROTECTED]> wrote:
>
> >> > Hi Joern,
>
> >> > I have come across an interesting problem regarding your jQuery
> >> > Validation script that I am sure you already have a solution to, but I
> >> > can't find it!
>
> >> > I need the validation rules to look at the form input IDs rather than
> >> > the form input names. I have a form that iterates 10 times (when you
> >> > click next), so the the names of the inputs increment by 1 each time,
> >> > whilst the IDs stay the same. (This is not my doing, so I have to live
> >> > with the naming convention!)
>
> >> > For example:
>
> >> > Form1 has input names field1_1, field2_1, field3_1 and input ids
> >> > field1, field2, field3
> >> > Form2 has input names field1_2, field2_2, field3_2 and input ids
> >> > field1, field2, field3
>
> >> > I originally thought your jQuery Validation script looked at the IDs
> >> > on the page, so the same validation rules would apply for field1
> >> > whether on form1 or form2. However this is not the case.
>
> >> > How do I change your script to look at the ID?
>
> >> > Many thanks in advance for your help.
>
> >> >Simon

Reply via email to