Problem/Motivation
I have a page with multiple autocompletes. They are displayed in different places so they are styled differently. The only unique attribute was ID, however, it changed paged to page.
Steps to reproduce
Add more than one search autocomplete and you will see #ui-id-1, #ui-id-2, #ui-id-3 etc with no unique/descriptive selector.
Data model changes
I simply added a data-input-ref attribute to the ui-autocomplete that would tell me exactly what input this autocomplete is from. It ends up being the machine name of the autocomplete.
Without the patch you see the rendered autocomplete as:
<ul id="ui-id-1" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" unselectable="on" data-sa-theme="minimal">
...
</ul>
With the patch:
<ul id="ui-id-1" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" unselectable="on" data-input-ref="your_autocomplete_machine_name" data-sa-theme="minimal">
...
</ul>
Comments
Comment #2
dom. commentedI am very sorry, but I can't see how this work.
Testing the patch, I have no
value.data('id')only possible values arekeyanddrupalSelectorhere.Is something like this patch okay for your needs ?
Comment #4
dom. commentedWill be added in 3.0 release for Drupal 10.
Comment #5
rondog469 commentedthank you @Dom! Yeah I am not too sure what I did with that first patch. I think I uploaded the wrong version at the time because it indeed does not work. Yours look good to me