CheckBox List - All going on?

This is a weird one . . . when I add a checkbox all the options toggle/on/off . . when I submit the field is a boolean, not an array of values. Thoughts?
14 Replies
bennett
bennett7mo ago
Also having this issue
LeandroFerreira
LeandroFerreira7mo ago
where? Could you explain what is the issue?
bennett
bennett7mo ago
I've placed a CheckboxList in a Wizard form thats in a custom Livewire Component.
CheckboxList::make('selected_manufacturers')
->label('Manufacturers')
->hint('Optional')
->options([
'fish' => 'Fish',
'cow' => 'Cow',
'horse' => 'Horse',
'chicken' => 'Chicken',
'pig' => 'Pig',
])
->columns(3)
CheckboxList::make('selected_manufacturers')
->label('Manufacturers')
->hint('Optional')
->options([
'fish' => 'Fish',
'cow' => 'Cow',
'horse' => 'Horse',
'chicken' => 'Chicken',
'pig' => 'Pig',
])
->columns(3)
bennett
bennett7mo ago
When I click on any of the options, all of them are selected:
No description
bennett
bennett7mo ago
@Leandro Ferreira Strangely, when dumping the form's state on submission, the value is true instead of an array of selected keys
No description
LeandroFerreira
LeandroFerreira7mo ago
Did you add $this->form->fill() in the mount method? Are you using statePath?
bennett
bennett7mo ago
I use $this->form->fill() to set some default values :
public function mount(): void
{
$this->form->fill(['filter_manufacturers' => 'no']);
}
public function mount(): void
{
$this->form->fill(['filter_manufacturers' => 'no']);
}
->statePath('data') ( Just the default variable choice )
LeandroFerreira
LeandroFerreira7mo ago
Could you please check if there is another field with the selected_manufacturers name? This doesn't make sense
bennett
bennett7mo ago
The issue seems to be with the way I'm conditionally assigning the Wizard\Step schema:
Wizard\Step::make('Manufacturers')
->description('Select Manufacturers')
->schema(function(Get $get){

return $get('selected_vendors') == null ?

[
Placeholder::make('info')
->label('')
->columnSpanFull()
->content(new HtmlString('<div class="info-notice py-1.5"> some text </div>'))
] :
[
ToggleButtons::make('filter_manufacturers')
->label("Filter selected Vendors by Manufacturer?")
->live()
->inline()
->options([
'yes' => 'Yes',
'no' => 'No',
])
->colors([
'yes' => 'info',
'no' => 'warning',
]),
CheckboxList::make('selected_manufacturers')
->label('Manufacturers')
->hint('Optional')
->options([
'fish' => 'Fish',
'cow' => 'Cow',
'horse' => 'Horse',
'chicken' => 'Chicken',
'pig' => 'Pig',
])
->columns(3)
];
}),
Wizard\Step::make('Manufacturers')
->description('Select Manufacturers')
->schema(function(Get $get){

return $get('selected_vendors') == null ?

[
Placeholder::make('info')
->label('')
->columnSpanFull()
->content(new HtmlString('<div class="info-notice py-1.5"> some text </div>'))
] :
[
ToggleButtons::make('filter_manufacturers')
->label("Filter selected Vendors by Manufacturer?")
->live()
->inline()
->options([
'yes' => 'Yes',
'no' => 'No',
])
->colors([
'yes' => 'info',
'no' => 'warning',
]),
CheckboxList::make('selected_manufacturers')
->label('Manufacturers')
->hint('Optional')
->options([
'fish' => 'Fish',
'cow' => 'Cow',
'horse' => 'Horse',
'chicken' => 'Chicken',
'pig' => 'Pig',
])
->columns(3)
];
}),
If I take out the conditional, and just return a CheckboxList, it works fine
LeandroFerreira
LeandroFerreira7mo ago
Try simplifying the example and testing it again. If the problem persists, consider opening an issue on GitHub
bennett
bennett7mo ago
ok - Is this a bad practice for conditionally rendering fields?
LeandroFerreira
LeandroFerreira7mo ago
no, I guess
awcodes
awcodes7mo ago
Typically you would put all the fields in the schema then use visible() or hidden() on each field or layout to handle the display. I think conditionally render different data points is going to lead to state issues, even if it does kinda work.
bennett
bennett7mo ago
Switching to visible() and hidden() did solve my issue
Want results from more Discord servers?
Add your server