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
bennett3w ago
Also having this issue
LeandroFerreira
where? Could you explain what is the issue?
bennett
bennett3w 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
bennett3w ago
When I click on any of the options, all of them are selected:
No description
bennett
bennett3w 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
Did you add $this->form->fill() in the mount method? Are you using statePath?
bennett
bennett3w 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
Could you please check if there is another field with the selected_manufacturers name? This doesn't make sense
bennett
bennett3w 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
Try simplifying the example and testing it again. If the problem persists, consider opening an issue on GitHub
bennett
bennett3w ago
ok - Is this a bad practice for conditionally rendering fields?
LeandroFerreira
no, I guess
awcodes
awcodes3w 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
bennett2w ago
Switching to visible() and hidden() did solve my issue