Trying to update Select field options when another field is updated?

Here is my code below. locations is a variable on my livewire component that contains the form schema
Toggle::make('floridaOnly')
->default(true)
->reactive()
->afterStateUpdated(function (Closure $set, $state) {
$this->locations = AlamoLocationsFormatter::getFilterOptions(
SearchAlamoVehicleLocations::handle()->body(), $state
);
})
->columnSpan(3),
Select::make('fromLocation')
->options($this->locations)
->searchable()
->required(),
Toggle::make('floridaOnly')
->default(true)
->reactive()
->afterStateUpdated(function (Closure $set, $state) {
$this->locations = AlamoLocationsFormatter::getFilterOptions(
SearchAlamoVehicleLocations::handle()->body(), $state
);
})
->columnSpan(3),
Select::make('fromLocation')
->options($this->locations)
->searchable()
->required(),
Not sure if "after state updated" is where this type of logic should go. But basically, I send the state in (true or false) and based on that i run a filter and return the locations. The locations value is being changed by this afterStateUpdated hook, but the options in the below select field "fromLocation" aren't being updated.
2 Replies
Dan Harrin
Dan Harrin2y ago
i think i replied on github
Dan Harrin
Dan Harrin2y ago
You dont need to store the options, you just pass a closure to the options() method. https://filamentphp.com/docs/2.x/forms/fields#dependant-selects
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Want results from more Discord servers?
Add your server