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
wyChoong16mo ago
How are you triggering the event? A normal listener with $refresh should work?
David Vincent
David Vincent16mo 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
wyChoong16mo 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
LeandroFerreira16mo ago
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 Vincent16mo ago
thanks, I will give it a try
Dan Harrin
Dan Harrin16mo 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 Vincent16mo ago
Great! Thanks Dan
LeandroFerreira
LeandroFerreira16mo ago
my bad, it is true