F
Filament9mo ago
Augus

Live function does not empty radio field

What I am trying to do: I want to have the Radio field 'ubn' be emptied whenever i change the select field 'relation'. Do note that the Radio options are filled with the Select change as seen in the options function of that field. What I did: I tried adding the afterStateUpdated to the select field as shown in the example, this was my best guess. Also tried the dehydrateStateUsing on the Radio field but that would empty it always. My issue: My issue is that although visually the radio is deselected whenever i change the Select field. But the Radio is not deselected on the "backend" as in it will go trough validation and i can still access it via the Get $get. Code:
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->required()
->options([
'Uw relaties' => auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})->toArray(),
'Leden' => User::with('contact')->get()->pluck('contact.full_name','contact.id')->toArray(),

])
->afterStateUpdated(fn (Set $set, ?string $state) => $set('ubn', '')),

Radio::make('ubn')
->label('UBN')
->required()
->disabled(empty($this->data['relation']))
->options(fn (Get $get ): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('name','id')->toArray() : ['#' => 'Selecteer eerst een relatie']
),
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->required()
->options([
'Uw relaties' => auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})->toArray(),
'Leden' => User::with('contact')->get()->pluck('contact.full_name','contact.id')->toArray(),

])
->afterStateUpdated(fn (Set $set, ?string $state) => $set('ubn', '')),

Radio::make('ubn')
->label('UBN')
->required()
->disabled(empty($this->data['relation']))
->options(fn (Get $get ): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('name','id')->toArray() : ['#' => 'Selecteer eerst een relatie']
),
Solution:
So had a solution from the Laravel Daily discord to add
live()
live()
to the Radio field and that worked.
Jump to solution
1 Reply
Solution
Augus
Augus9mo ago
So had a solution from the Laravel Daily discord to add
live()
live()
to the Radio field and that worked.