Skip to content

Commit 5ecd2b6

Browse files
committed
Default checkbox elements to an empty array
1 parent dccb788 commit 5ecd2b6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

app/Livewire/CustomFieldSetDefaultValuesForModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ private function populatedSelectedValuesArray(): void
8181
{
8282
$this->fields->each(function ($field) {
8383
$this->selectedValues[$field->db_column] = $this->getSelectedValueForField($field);
84+
85+
// if the element is a checkbox and the value was just sent to null, make it
86+
// an array since Livewire can't bind to non-array values for checkboxes.
87+
if ($field->element === 'checkbox' && is_null($this->selectedValues[$field->db_column])) {
88+
$this->selectedValues[$field->db_column] = [];
89+
}
8490
});
8591
}
8692

0 commit comments

Comments
 (0)