F
Filament15mo ago
Augus

Select field issues with combination of Live + Disabled.

So i have been playing around whole night to get this to work but im simply not able to. What i want to do is pretty simple though; 1. I want to have the "Location" (UBN) select field to be disabled. 2. User selects a "Contact" (Relatie) in the first select field. 3. When a "Contact" is selected i want to search for all related "Location" objects for that contact and place them in field 2 as options. 3. When options are loaded or when User selected the "Contact" in field #1 i want to enable field #2. 4. User selects "Location" (UBN)
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->options(
auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})
),
Select::make('ubn')
->searchable()
->label('UBN')
->disabled(empty($this->data['relation']))
->options(fn (Get $get
): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('ubn',
'id') : ['#' => 'Selecteer eerst een relatie']
),
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->options(
auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})
),
Select::make('ubn')
->searchable()
->label('UBN')
->disabled(empty($this->data['relation']))
->options(fn (Get $get
): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('ubn',
'id') : ['#' => 'Selecteer eerst een relatie']
),
Above simply does not load any options for field #2 (UBN) but this is mainly because the ->disabled(empty($this->data['relation'])) cause removing this let's both fields work as expected. But you can imagine that having the second field disabled when there is no option selected in the first field would be more user friendly. Am i doing something wrong or is this simply not possible?
7 Replies
Augus
AugusOP15mo ago
This does work as expected with the Radio field 🤷‍♂️.
Eugen Pașca
Eugen Pașca15mo ago
Have you tried to have a callable for the disabled method?
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->options(
auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})
),
Select::make('ubn')
->searchable()
->label('UBN')
->disabled(fn(Get $get) => empty($get('relation'))
->options(fn (Get $get
): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('ubn',
'id') : ['#' => 'Selecteer eerst een relatie']

),
Select::make('relation')
->searchable()
->label('Relatie')
->live()
->options(
auth()->user()->relations->mapWithKeys(function ($relation) {
return [$relation->id => $relation->full_name];
})
),
Select::make('ubn')
->searchable()
->label('UBN')
->disabled(fn(Get $get) => empty($get('relation'))
->options(fn (Get $get
): Collection|array => ! empty($get('relation')) ? Contact::find($get('relation'))->locations()->pluck('ubn',
'id') : ['#' => 'Selecteer eerst een relatie']

),
gergo85
gergo8514mo ago
Not working for me. I tried several cases too. My code:
Select::make('print_all')
->options([
1 => 'Yes',
0 => 'No'
])
->default(1)
->selectablePlaceholder(false)
->live()
->required(),
Select::make('select_label')
->options($this->labels)
->default(array_key_first($this->labels))
->selectablePlaceholder(false)
->disabled(fn (Get $get) => $get('print_all') == 1)
->live()
->required(),
Select::make('print_all')
->options([
1 => 'Yes',
0 => 'No'
])
->default(1)
->selectablePlaceholder(false)
->live()
->required(),
Select::make('select_label')
->options($this->labels)
->default(array_key_first($this->labels))
->selectablePlaceholder(false)
->disabled(fn (Get $get) => $get('print_all') == 1)
->live()
->required(),
Augus
AugusOP14mo ago
Yea same, great idea but still didn't work :(.
Mikazor
Mikazor13mo ago
Someone figured it out?
Augus
AugusOP12mo ago
Using the radio field worked, select didn't Think its a bug tbh
Dennis Koch
Dennis Koch12mo ago
Yes it is an unsolved bug. We can’t disable choices.js after it was initiated
Want results from more Discord servers?
Add your server