CheckboxList value is always a single value?!
Hi experts! Another Beginer-Question π
I have a Dashboard-Widget that hosts a form.
So it implements
HasForms
and uses the trait InteractsWithForms
My form looks something like this:
protected function getFormSchema(): array
{
$countryCodes = ['DE' => 'DE', 'FR' => 'FR', 'CN' => 'CN'] ;
return [
CheckboxList::make('origin')
->options( $countryCodes )
->bulkToggleable(true)
->columns(3),
CheckboxList::make('destination')
->options( $countryCodes )
->bulkToggleable(true)
->columns(3),
];
}
All Formdata is written to public property $data
protected function getFormStatePath(): string
{
return 'data';
}
My problem is, that any of the CheckboxLists always contains just one option as value, even if all checkboxes are selected.
It doesn't matter if I get the form values with $this->form->getState()
or via $this->data
.
So my question is: How do I get ALL values of the selected checkboxes? (as a JSON string or an array.)2 Replies
did you call
$this->form->fill()
No. When should fill() be called?
OK. I call $this->form->fill() now inside the mount() method. Now it's working as expected. Whats the reason for taht?
And again: thank you @Dan Harrin , for your help!