Filament 3.x: How to open a modal from blade template
Hey together I have a modal within a livewire component which is build with Action::make('something')->form(...). At the moment it renders a trigger button which opens the modal. In a special case i need to open this modal dynamically on page load. How can I achieve this?
13 Replies
Okay I was not specific enough. the modal should open after a user was logged in. so the page could be any page of the app.
isnt it possible to call ich directly over e.g. livewire dispatch? I found some documentation with custom blade template, but i want/need to use the form builder here.
You can use the modal component and add it via an render hook after login.
https://filamentphp.com/docs/3.x/support/blade-components/modal
but i want/need to use the form builder here.Well, that's rules it out π My idea: - On login write to session and check that session key. - Inject a custom Livewire component via render hook.
the livewire component is already there and injected in the page header but uses the FormBuilder trigger button solution xD
here is a sample snippet of the blade template of the livewire component:
but the open-modal part is not working atm
this componeent is loaded beside the user profile icon
Because the
open-modal
event needs the modal idyep and i dont have one
It's probably generated from the action name. I think you might find the modal in the source code via DevTools
hmm i have searched it there but did not find it. but it is completely logic -> i am in the else part and so the $this->customerLocationModalAction is never triggered.
okay the whole requirement of this feature: admin should get a button which opens a modal where he/she can select the location (currently implemented). the normal user should not see this button, but after login the same modal should open and force him to select the location.
Solution
is this a kind of preloading of the action without rendering it/the button?
It will trigger your action when livewire initializes
uuuuhhh nice π thanks a lot! I only had to cover the mountAction part inside an if which should only be called when user is not a admin π
this works now as expected