diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index faa00949..bb5b58ef 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -7,7 +7,7 @@ {% set vertical = field.style == 'vertical' %} {% if not blueprints or (blueprints.schema.type(field.type)['input@'] ?? true) is same as(true) %} - {% set default = field.default %} + {% set default = default ?? (field.evaluate and field.default and field.default is not iterable ? evaluate(field.default) : field.default) %} {% set toggleable = field.toggleable ?? false %} {% if toggleable %} {% set originalValue = originalValue is defined ? originalValue : value %} diff --git a/templates/forms/fields/checkboxes/checkboxes.html.twig b/templates/forms/fields/checkboxes/checkboxes.html.twig index ba9a6506..1be01fb3 100644 --- a/templates/forms/fields/checkboxes/checkboxes.html.twig +++ b/templates/forms/fields/checkboxes/checkboxes.html.twig @@ -1,10 +1,19 @@ {% extends "forms/field.html.twig" %} {% set originalValue = value %} -{% set value = (value is null ? field.default : value) %} -{% if field.use == 'keys' and field.default %} - {% set value = field.default|merge(value) %} -{% endif %} + +{% set default = {} %} +{% for key, default_value in field.default %} + {% set default_value = (default_value and field.evaluate) ? evaluate(default_value) : default_value %} + {% if default_value %} + {% if field.use == 'keys' %} + {# NOTE: The brackets around the key are important! #} + {% set default = default|merge({(key): default_value} ) %} + {% else %} + {% set default = default|merge([default_value]) %} + {% endif %} + {% endif %} +{% endfor %} {% block global_attributes %} {{ parent() }} diff --git a/templates/forms/fields/hidden/hidden.html.twig b/templates/forms/fields/hidden/hidden.html.twig index 8506fa59..3b368a81 100644 --- a/templates/forms/fields/hidden/hidden.html.twig +++ b/templates/forms/fields/hidden/hidden.html.twig @@ -2,7 +2,6 @@ {% block field %} -{% set value = value ?: (field.value ?? (field.evaluate ? evaluate(field.default) : field.default)) %} {% set input_value = value is iterable ? value|join(',') : value|string %}