How can I dynamically update my Select options based on an API

I've got a textInput where a user can enter their zipcode/postcode and a button that does a lookup via an API. I'd like to find a way to make the options in the Select update. Is it possible?
private $addresses;
...

TextInput::make('addressLookupText')
->label('Address Lookup'),
Actions::make([
Action::make('Address Lookup Button')
->label('Find Address')
->action(function (Get $get) {
$this->addresses = $this->findAddresses($get('addressLookupText'));
}),
]),
Select::make('addresses')
->options($this->addresses)
->label('Select an address'),
private $addresses;
...

TextInput::make('addressLookupText')
->label('Address Lookup'),
Actions::make([
Action::make('Address Lookup Button')
->label('Find Address')
->action(function (Get $get) {
$this->addresses = $this->findAddresses($get('addressLookupText'));
}),
]),
Select::make('addresses')
->options($this->addresses)
->label('Select an address'),
Solution:
Why two separate fields? I’m doing something similar but with just one select (using the getSearchResultsUsing method on the select). Works great. When a result is selected I also set some other fields.
Jump to solution
3 Replies
Solution
Tim van Heugten
Tim van Heugten5mo ago
Why two separate fields? I’m doing something similar but with just one select (using the getSearchResultsUsing method on the select). Works great. When a result is selected I also set some other fields.
Tim van Heugten
Tim van Heugten5mo ago
Can’t access my code right now, but very similar as what @Dennis Koch is doing here: https://v2.filamentphp.com/tricks/geocoding-field-using-select-component
Filament
Geocoding field using Select component by Dennis Koch - Tricks - Fi...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
urbycoz
urbycoz5mo ago
This is perfect. Thanks so much!