- Issue created by @ericgsmith
- 🇳🇿New Zealand ericgsmith
Ok, looks like there is many discussions in core about this behavior:
- 🇦🇹Austria drunken monkey Vienna, Austria
drunken monkey → made their first commit to this issue’s fork.
- 🇦🇹Austria drunken monkey Vienna, Austria
Thanks a lot for reporting this problem, and sorry it took me a while to get back to you!
Unfortunately you are right that it doesn’t really seem easy to fix this problem ourselves as Core’s
autocomplete.js
doesn’t provide the required extension points.
It seemsextractLastTerm()
is called from bothsearchHandler()
(to determine whether the input is long enough to even attempt to autocomplete) andsourceData()
(to actually provide the autocomplete suggestions, either from cache or by sending the request).Since both are actually set on
Drupal.autocomplete.options
, however, it does seem like it might in fact be possible to override them? So, in theory we could probably provide our own versions of them for our own autocomplete elements and leave the other ones unchanged.
However, if we don’t want to duplicate their code (and manually have to port any changes Core makes to them) we’d then have to set some kind of global variable that this is one of our elements, then call the parent and then also overrideDrupal.autocomplete.splitValues()
globally to change what it does (return single token or call old method) based on that global variable.
Really not ideal, but feasible in theory. However, hopefully one of the Core issues will get fixed and it doesn’t have to come to this. I’d wait for now to see what happens in Core.Note, also, that (it seems) we would only have to fix
splitValues()
, asextractLastTerm()
just uses that internally. If that method only returns a single token, then that token is also whatextractLastTerm()
will return.Anyways, thanks again for reporting!