Select::searchable() is not reactive?

Here's my screen record: https://www.loom.com/share/67e1b9b57e174bf3bc727ff7802d822c The rest of the fields are working except for the select dropdown. Here's my snippet :
Select::make('state')
->options(us_states())
->disabled(fn(Closure $get) => !$get('address_type') )
->required()
->searchable()
->reactive()
->afterStateUpdated(function(Closure $get, $state){
}),
Select::make('state')
->options(us_states())
->disabled(fn(Closure $get) => !$get('address_type') )
->required()
->searchable()
->reactive()
->afterStateUpdated(function(Closure $get, $state){
}),
7 Replies
moaaz_m_f
moaaz_m_f2y ago
can you share this function
us_states()
us_states()
awcodes
awcodes2y ago
$get(‘address_type’) is not returning a Boolean. You need to cast it as one to use it this way.
vahnmarty
vahnmartyOP2y ago
It is just my helper method in calling all the us states.
if (! function_exists('us_states')) {
function us_states() {
$file = public_path('data/states.json');
$json = file_get_contents($file);
$data = json_decode($json, true);
$array = [];

foreach($data as $state)
{
$array[$state] = $state;
}

return $array;
}
}
if (! function_exists('us_states')) {
function us_states() {
$file = public_path('data/states.json');
$json = file_get_contents($file);
$data = json_decode($json, true);
$array = [];

foreach($data as $state)
{
$array[$state] = $state;
}

return $array;
}
}
states.json
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
Andrew Wallo
Andrew Wallo2y ago
Searchable selects cant be disabled and reactive unless you also pass a closure inside the the searchable() method to check if the component is disabled or not Or at least I’m pretty sure something like this:
Select::make('state')
->options(us_states())
->disabled(fn(Closure $get) => !$get('address_type') )
->required()
->searchable(fn (Select $component) => !$component->isDisabled()),
->reactive(),
Select::make('state')
->options(us_states())
->disabled(fn(Closure $get) => !$get('address_type') )
->required()
->searchable(fn (Select $component) => !$component->isDisabled()),
->reactive(),
vahnmarty
vahnmartyOP2y ago
Did not work.
protected function getFormSchema()
{
return [
Select::make('address_type')
->options(AddressType::asSameArray())
->required()
->reactive(),
Select::make('state')
->options([
'Florida' => 'Florida'
])
->disabled(fn(Closure $get): bool => $get('address_type') ? false : true )
->searchable(fn (Select $component) => !$component->isDisabled())
->required()
->searchable()
->reactive()
->afterStateUpdated(function(Closure $get, $state){

}),
];
}
protected function getFormSchema()
{
return [
Select::make('address_type')
->options(AddressType::asSameArray())
->required()
->reactive(),
Select::make('state')
->options([
'Florida' => 'Florida'
])
->disabled(fn(Closure $get): bool => $get('address_type') ? false : true )
->searchable(fn (Select $component) => !$component->isDisabled())
->required()
->searchable()
->reactive()
->afterStateUpdated(function(Closure $get, $state){

}),
];
}
awcodes
awcodes2y ago
Remove your second searchable().
vahnmarty
vahnmartyOP2y ago
Damn that worked! Thanks guys, I think the ->searchable callback fixed the issue.
Want results from more Discord servers?
Add your server