Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By baland on
I have a textfield that uses autocomplete. It basically works with the default misc/autocomplete.js. Now I want to override this with my own file. So I have in modules/custom/myModule/myModule.info.yml:
libraries-override:
core/drupal.autocomplete:
js:
misc/autocomplete.js: js/autocomplete.js
with having my autocomplete.js in modules/custom/myModule/js. However, this is ignored. The page still uses core/misc/autocomplete.js. I tried several variants of the override entry, but nothing works. Any idea?
Comments
Make sure you're not using a base theme.
This is correct and assumes the root of the theme folder. But issue was that I was using 'classy' as my base theme, in order to get the override working I had to put the override in the 'classy.info.yml' which isn't advisable from core. So I moved it to the contrib themes folder and changed it's name and now my override works fine - hopefully this will help someone else...
What worked for me
I'm using a custom theme and a custom module, and the libraries-override solution didn't work for me.
I tried to override it on the custom theme, and on the custom module, but with no luck.
What worked for me was this:
In my case, I added it to the element:
The reason to add drupalSettings is to provide the possibility to send variables to the autocomplete file.
For instance to modify some of the options of the autocomplete.