From 55c934efb3519285d8acbcf40bb13ddd14c6f8af Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 9 Jan 2021 10:13:14 +0100 Subject: [PATCH 1/2] Fix #471 checkboxes state when all boxes are empty --- classes/Form.php | 3 +++ templates/forms/fields/checkboxes/checkboxes.html.twig | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/Form.php b/classes/Form.php index dad2974b..51a689c6 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -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++; } diff --git a/templates/forms/fields/checkboxes/checkboxes.html.twig b/templates/forms/fields/checkboxes/checkboxes.html.twig index ba9a6506..8f548598 100644 --- a/templates/forms/fields/checkboxes/checkboxes.html.twig +++ b/templates/forms/fields/checkboxes/checkboxes.html.twig @@ -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 %} From c107f268c1365a28cf42026cace308d8737fcf20 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Tue, 12 Jan 2021 18:26:20 +0100 Subject: [PATCH 2/2] Remove not required default setting --- templates/forms/fields/checkboxes/checkboxes.html.twig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/templates/forms/fields/checkboxes/checkboxes.html.twig b/templates/forms/fields/checkboxes/checkboxes.html.twig index 8f548598..60597ebd 100644 --- a/templates/forms/fields/checkboxes/checkboxes.html.twig +++ b/templates/forms/fields/checkboxes/checkboxes.html.twig @@ -1,10 +1,6 @@ {% extends "forms/field.html.twig" %} {% set originalValue = value %} -{% set value = (value is null ? field.default : value) %} -{% if field.use == 'keys' and field.default and value is null %} - {% set value = field.default|merge(value) %} -{% endif %} {% block global_attributes %} {{ parent() }}