Problem/Motivation
I noticed that the exposed filter for proximity had the autocomplete working only sometimes.
While debugging putting breakpoints on the geocoder js code always resulted on the correct behavior but without breakpoints the geocoder js code runs first, sets an autocomplete on the input element then sets the "form-autocomplete" class which triggers the Drupal.behaviours.autocomplete and deletes the previous autocomplete configuration overwriting it with an invalid new one.
Removing the .addClass("form-autocomplete"); solves the issue but then I don't get styling for the input.
Note that the order of execution of Drupal behaviours AFAIK can't be determined .
Steps to reproduce
I am on Drupal 11.4.4
Configure a view with an exposed autocomplete origin.
Maybe you get the bug with that configuration but if not you can simulate the Drupal autocomplete behaviour running later than geocoder's with this dirty wait
Drupal.behaviors.autocomplete = {
attach(context) {
var sleep = function(ms){
var waitUntil = new Date().getTime() + ms;
while(new Date().getTime() < waitUntil) continue;
};
sleep(2000);
// Act on textfields with the "form-autocomplete" class.
once('autocomplete', 'input.form-autocomplete', context).forEach(
...
Proposed resolution
I'm not sure how avoid the autocomplete conflict. So far I'm patching geocoder to remove the .addClass("form-autocomplete"); line.
Remaining tasks
Come up with a solution
User interface changes
API changes
Data model changes
Issue fork geocoder-3611573
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
velmir_taky commentedWe build our own jQuery UI autocomplete, then add the form-autocomplete class for styling — but that's also what core's autocomplete behavior hooks onto, so when it runs after ours it re-inits the widget and clobbers our source (order isn't guaranteed => intermittent).
Fix: claim core's once id ourselves —
once("autocomplete", [element]);— so core skips the element and the styling stays.Added a
FunctionalJavascripttest forcing the bad order: red before, green after.Comment #5
rodrigoaguileraI reviewed the code and it makes sense to take over the autocomplete.
Also tested manually and I can't trigger the race condition anymore.