Autocomplete won't work inside Wire Elements Modal #12
-
Hi Josh, Autocomplete is broken if I place the it inside the wire elements modal which is a livewire popup dialog-box component. The console warns that "Alpine Expression Error: autocomplete is not defined". But it works when it is not placed inside any modal or is dynamically created. The reason is due to autocomplete function defined in resources/views/autocomplete.blade.php was not registered into the window object when it is called by wire elements modal. A relevant post discussing that alpine not working inside the wire element modal might be having the same issue as this. I suspect the @livewire(...) blade directive used inside the wire elements modal does not register functions defined inside the components when called dynamically. The temporary solution was to assign the autocomplete function to window.autocomplete inside the autocomplete.blade.php However, I was not able to publish the autocomplete.blade.php to my views folder to do this. Any idea how can I make it work inside wire elements modal? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@kfkok thanks for reporting! I haven't used the Wire Elements Modal, but going off what you described, the reason it won't be working is because Livewire (currently) won't dynamically load scripts. It's an issue with any Alpine based component using an external function. Personally, I'm hesitant to assign package scripts to the window object, as it runs the risk of conflicts. One work around would be, if you add an autocomplete component somewhere on the page and hide it. Then when the modal dynamically loads one, it will work, as the function already exists on the page. This issue is something we've been working on fixing in Livewire, but we ran into some breaking changes, so it's now going to have to wait until V3 is released. The other way around it would be to not use the Wire Elements Modal. I use a modal, that I took from Jetstream and modified, that just makes use of Alpine, that way there is no dynamic Hope this helps! |
Beta Was this translation helpful? Give feedback.
@kfkok thanks for reporting!
I haven't used the Wire Elements Modal, but going off what you described, the reason it won't be working is because Livewire (currently) won't dynamically load scripts. It's an issue with any Alpine based component using an external function.
Personally, I'm hesitant to assign package scripts to the window object, as it runs the risk of conflicts.
One work around would be, if you add an autocomplete component somewhere on the page and hide it. Then when the modal dynamically loads one, it will work, as the function already exists on the page.
This issue is something we've been working on fixing in Livewire, but we ran into some breaking changes, so it's now go…