How to execute javascript within a modal
I have a modal that is initated with an action:
This opens the modal slideover correctly, and I see the correct content. However, I need to execute some javascript after the modal loads. I've tried updating my blade to do this:
I do have the
@stack
in my app.blade.php file:
But that console.log
doesn't execute. So, I have two questions:
1. How do I execute JS in a modal
2. There will be several table rows with the same action, that execute the same JS - is there a better way to do this?7 Replies
have you tried to use wire:init in your modal component
https://livewire.laravel.com/docs/wire-init
Laravel
wire:init | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
I have not, I'll try it first thing - thanks!
It seems as if
wire:init
is intended for calling actions - I don't see how that would allow me to execute JS in a modal - am I missing your meaning?
That did lead me to https://livewire.laravel.com/docs/javascript but when I do something simple like:
It just renders @script @endscript
and never logs.Laravel
JavaScript | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
What about using alpine x-init
https://alpinejs.dev/directives/init
Thanks, I'll take a look at that as well. Right now I at least have my JS firing with a combo of:
component blade file:
<div class="wrapper flex flex-col" wire:init="initScanner">
component class:
js
I have no idea if this is the best way to do this yet. I'm still trying to figure out the relationship between Filament, Livewire, and Alpine and knowing when to use what where πYou can also dispatch it using
mountUsing
method I think