Skip to content

Commit

Permalink
Fixed evaluating default value in hidden field (thanks @NicoHood)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jan 8, 2021
1 parent b3e80f8 commit f61725c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#bugfix)
* Fixed state of the checkbox if no value is provided
* Fixed evaluating default value in `hidden` field (thanks @NicoHood)

# v4.3.0
## 12/14/2020
Expand Down
3 changes: 1 addition & 2 deletions templates/forms/fields/hidden/hidden.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

{% block field %}

{% set value = value ?: field.value|default(field.default) %}
{% set value = field.evaluate ? evaluate(value) : value %}
{% 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

2 comments on commit f61725c

@NicoHood
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed, that this fix breaks the evaluation itself. The reason why this happens is, that the current code itself is a bit missleading:

{% set value = value ?: field.value|default(field.default) %}

When this line gets executed, value is already set to field.default. So |default(field.default) will never happen anyways. The code worked before, as value was evaluated.

Now with the new code value is taken preferred to the evaluation code (field.value ?? (field.evaluate ? evaluate(field.default) : field.default)), so value will always be field.default, always no evaluated.

PR #473 fixes that issue and adds a more general evaluation support.

@mahagr
Copy link
Member Author

@mahagr mahagr commented on f61725c Jan 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as I didn't take the field.html.twig into account.

Please sign in to comment.