Skip to content

Commit

Permalink
Fix getgrav#471 checkboxes state when all boxes are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood committed Feb 11, 2021
1 parent 817d553 commit 55c934e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions classes/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ public function post()
if ($field['type'] === 'checkbox' || $field['type'] === 'switch') {
$data[$name] = isset($data[$name]) ? true : false;
}
if ($field['type'] === 'checkboxes' && !isset($data[$name])) {
$data[$name] = [];
}
$i++;
}

Expand Down
2 changes: 1 addition & 1 deletion templates/forms/fields/checkboxes/checkboxes.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% set originalValue = value %}
{% set value = (value is null ? field.default : value) %}
{% if field.use == 'keys' and field.default %}
{% if field.use == 'keys' and field.default and value is null %}
{% set value = field.default|merge(value) %}
{% endif %}

Expand Down

0 comments on commit 55c934e

Please sign in to comment.