Skip to content

Commit

Permalink
Added evaluate option for all non-iterable field types and checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood committed Jan 9, 2021
1 parent 98a8ec0 commit 03c9147
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion templates/forms/default/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
17 changes: 13 additions & 4 deletions templates/forms/fields/checkboxes/checkboxes.html.twig
Original file line number Diff line number Diff line change
@@ -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() }}
Expand Down
1 change: 0 additions & 1 deletion templates/forms/fields/hidden/hidden.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<input data-grav-field="hidden" data-grav-disabled="false" type="hidden" class="input" name="{{ (scope ~ field.name)|fieldName }}" value="{{ input_value|e('html_attr') }}" />
Expand Down

0 comments on commit 03c9147

Please sign in to comment.