Skip to content

Commit

Permalink
fix: allow integer zero (0) value when filling attribute
Browse files Browse the repository at this point in the history
When options to the field have integer keys including zero, like:
```
[
    0 => 'Administrator',
    1 => 'Moderator',
    2 => 'Subscriber',
    3 => 'Super administrator'
];
```
then the field silently drops the zero value when the field fills the
attribute.

Closes Silvanite#32
  • Loading branch information
tzelleke committed May 6, 2020
1 parent 5bd398f commit a6a40df
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
if (!is_array($choices = $request[$requestAttribute])) {
$choices = collect(explode(',', $choices))->map(function ($choice) {
return ($this->shouldNotTypeCast()) ? $choice : $this->castValueToType($choice);
})->filter()->all();
})->filter(function ($value) {
/**
* Filtering out "falsy" values but allowing for int value zero (0)
*/
return $value === 0 ? true : $value;
})->all();
}

$model->{$attribute} = $choices;
Expand Down

0 comments on commit a6a40df

Please sign in to comment.