The ID property for DOM objects must be unique per object:

http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

... but subform element doesn't rename the IDs in the subform's components, leading to multiple elements with IDs of 'edit-body', etc.

Aside from conforming to HTML standards, fixing this would allow javascript programmers to reach these fields easily.

Some recursive prefixing of IDs would work -- exactly like what is done with the #name property already -- but that would then need to be un-wrapped in subform_element_validate and subform_element_submit. (Or so I assume. I don't know the Forms API internals. I don't even want to know the subform_element internals. =)

I may submit a patch if nothing is pending ...

Comments

fago’s picture

that sounds great, however it might introduce troubles when forms try to mark errors on elements per id. Then the element won't be found anymore .. :/

mykle’s picture

It seems like the only place in the system where this ID stuff is a problem is inside the browser. The browser returns all the data by name, not by ID.

How could i hook into form_builder to adjust the IDs only in the HTML that gets generated, while leaving
the actual form array untouched?

mykle’s picture

Incidentally, aside from duplicating the IDs due to subforms having the same element names as their enclosing forms, addnode also uses the same ID on the span, the select box and the link in the select list it creates.

Not to rub it in, but at least that part of the wrongness seems un-necessary, and hopefully easy to fix.

mykle’s picture

Sorry ... this part is actually a bug on addnode. I have filed it as such. I am groping with both of them at once right now, and I get confused sometimes.

mykle’s picture

Do the drupal internals search through the $form array by '#id' ? Or is your concern just with javascript?

I thought setting the '#id' field was only going to affect the rendering of the HTML ...

fago’s picture

hm, I think it only affects html.. furthermore the issues with the errors I mentioned shouldn't be a problem, as form_set_error is supposed to be only used with the name of the element