Form Select options reload

Is there a way to send an event to a form select component to reload its options ? Or do I have to registerListeners for this specific select
8 Replies
wyChoong
wyChoong2y ago
How are you triggering the event? A normal listener with $refresh should work?
David Vincent
David VincentOP2y ago
My question is how to trigger such event, and a form field is not a livewire component, so I can't trigger a $refresh on a field but on the livewire component which contains the select field.
wyChoong
wyChoong2y ago
https://laravel-livewire.com/docs/2.x/events trigger from js/alpinejs, then $refresh on the livewire component
Livewire
Events | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
LeandroFerreira
Something like this?
Select::make('mySelect')
->options(
//my query
)
->registerListeners(['updateOptions' => [function ($component) {
$component->options(
//my new query
);
}]]),
Select::make('mySelect')
->options(
//my query
)
->registerListeners(['updateOptions' => [function ($component) {
$component->options(
//my new query
);
}]]),
$livewire->dispatchFormEvent('updateOptions');
$livewire->dispatchFormEvent('updateOptions');
David Vincent
David VincentOP2y ago
thanks, I will give it a try
Dan Harrin
Dan Harrin2y ago
listeners arent gonna do anything here the options are stored in js if you pass a callback to options(), the select should refresh them each time you open it
David Vincent
David VincentOP2y ago
Great! Thanks Dan
LeandroFerreira
my bad, it is true

Did you find this page helpful?