Skip to content

Commit

Permalink
Fixed default value to come from the Form in overridable field (tha…
Browse files Browse the repository at this point in the history
…nks @NicoHood)
  • Loading branch information
mahagr committed Jan 8, 2021
1 parent f61725c commit 98a8ec0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [](#bugfix)
* Fixed state of the checkbox if no value is provided
* Fixed evaluating default value in `hidden` field (thanks @NicoHood)
* Fixed default value to come from the `Form` in overridable field (thanks @NicoHood)

# v4.3.0
## 12/14/2020
Expand Down
5 changes: 3 additions & 2 deletions templates/forms/default/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
{% 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 toggleable = field.toggleable ?? false %}
{% if toggleable %}
{% set originalValue = originalValue is defined ? originalValue : value %}
{% set toggleableChecked = originalValue is not null %}
{% elseif field.overridable %}
{% set toggleable = true %}
{% set default = form.getDefaultValue(field.name) ?? field.default %}
{% set default = form.getDefaultValue(field.name) ?? default %}
{% set toggleableChecked = value is not null and value != default %}
{% endif %}

{% set cookie_name = 'forms-' ~ form.name ~ '-' ~ field.name %}
{% set value = value ?? (get_cookie(cookie_name) is not null ? get_cookie(cookie_name) : field.default) %}
{% set value = value ?? (get_cookie(cookie_name) is not null ? get_cookie(cookie_name) : default) %}

{% if (field.yaml or field.validate.type == 'yaml') and value is iterable %}
{% set value = value|toYaml %}
Expand Down

0 comments on commit 98a8ec0

Please sign in to comment.