Help with dependable select

I've a dependable select 'province' that depends on the select 'country', both of the inputs are nested within a repeater. the problem is with the province select, as you can see in the code, if i set the fallback return value for options to
`['' => '']
`['' => '']
` it works as expected (but it leave an extra padding space under the placeholder) but if i simply return an empty array, the select wouldn't react or change when i change the country, can anyone explain please? here's the code; ```php Select::make('country_id') ->label('Pays') ->options(CoreCountry::pluck('name', 'id')) ->native(false) ->searchable() ->live() ->afterStateUpdated(function ($get, $set, $livewire) { $set('province_id', null); }), Select::make('province_id') ->label('Province') ->options(function ($get) { $country_id = $get('country_id'); if ($country_id) { return CoreProvince::where('country_id', $country_id)->pluck('name', 'id'); } else { return ['' => '']; } }) ->searchable(),
2 Replies
toeknee
toeknee2mo ago
Select::make('country_id')
->label('Pays')
->options(CoreCountry::pluck('name', 'id'))
->native(false)
->searchable()
->live()
->afterStateUpdated(function ($get, $set, $livewire) {
$set('province_id', null);
}),

Select::make('province_id')
->label('Province')
->visible(fn($get) => !empty($get('country_id')))
->options(function ($get) {
$country_id = $get('country_id');
if ($country_id) {
return CoreProvince::where('country_id', $country_id)->pluck('name', 'id');
} else {
return ['' => ''];
}
})
->searchable(),
Select::make('country_id')
->label('Pays')
->options(CoreCountry::pluck('name', 'id'))
->native(false)
->searchable()
->live()
->afterStateUpdated(function ($get, $set, $livewire) {
$set('province_id', null);
}),

Select::make('province_id')
->label('Province')
->visible(fn($get) => !empty($get('country_id')))
->options(function ($get) {
$country_id = $get('country_id');
if ($country_id) {
return CoreProvince::where('country_id', $country_id)->pluck('name', 'id');
} else {
return ['' => ''];
}
})
->searchable(),
Would then hide the province when country_id isn't set and as such means nothing will be amiss
loading_personality
i think problem is with the first init, for instance if the first country that i select has no provinces, the fetch would never work. On the other hand if the first country that i select has provinces then the select would function as expected
Want results from more Discord servers?
Add your server