Skip to content

Commit

Permalink
Be a little more strict in picking 'selected' options: Only use the f…
Browse files Browse the repository at this point in the history
…allback, if there's no valid id set.
  • Loading branch information
bobdenotter committed Mar 16, 2015
1 parent 10ba197 commit 69d287f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/view/twig/editcontent/fields/_select.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
{% set selection = [ selection ] %}
{% endif %}

{# If the current selection contains an existing id, we must use _only_ the id, and not accept a fallback. #}
{% if selection|first in values|keys %}
{% set onlyids = true %}
{% else %}
{% set onlyids = false %}
{% endif %}

{% set attr_select = {
class: option.class,
id: key,
Expand All @@ -55,7 +62,7 @@
{% set is_array = (value is iterable and (value | length) > 1) %}
{% set attr_opt = {
value: id,
selected: id in selection or (is_array ? value[0] : value) in selection,
selected: id in selection or (not onlyids and (is_array ? value[0] : value) in selection),
} %}

<option{{ macro.attr(attr_opt) }}>{{ is_array ? value[0:]|join(' / ') : value }}</option>
Expand Down

0 comments on commit 69d287f

Please sign in to comment.