While working on the Rules UI I stumbled on a big issue:
drupal_html_id ensures that HTML IDs are always unique, even when forms are outputted multiple times on the same page. It does that, by appending a counter to the string(This was introduced here: #384992). So if your site replaces certain content using AJAX, all the IDs will be changed and that will cause problems to any JavaScript that wants to use an element, which finds it by its ID.
In my case, for example, the machine name script isn't able to find the input form, from which the label is read(but i think it also conflicts with the table drag script).
Reloading only certain parts of the form will probably not solve the issue(because of the table drags) and I'm certain there are many cases, which conflict with this issue in similar way.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | label-gets-lost.jpg | 117.74 KB | robertdouglass |
Comments
Comment #1
fagoyep, that's indeed weird. While drupal_html_id() is fine to ensure unique ids, it should not change the IDs of already previously existing elements - JS stuff often relies on IDs for finding HTML elements. However still the generated JS code should be able to deal with the generated IDs. Thus setting priority to normal.
Comment #2
rfaysubscribe
Comment #3
robertdouglass commentedI wonder if this is related to the bug where Label fields get reset if you change the dropdowns while adding a field? (see screenshot)
Comment #4
casey commented@robertDouglass see #735204: vanishing label text from manage fields page
Comment #5
dawehnerSubscribe
Someone suggested to not rely on form id's anymore.
Comment #6
chalee commentedHas a solution or at least a temporary fix found for this issue?
Comment #7
rfayBasically, you can't use HTML IDs any more for targeting things in CSS or JS. You have to use something else.
I'm going to call this a duplicate of #1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests
Comment #8
chalee commented@rfay: What is that 'something else' that we can use. I tried to use classes e.g
and HTML attributes like name e.g
but all in vain. Please help.