<commit_before>{% extends "forms/field.html.twig" %}

{% block global_attributes %}
    data-grav-selectize="{{ (field.selectize is defined ? field.selectize : {})|json_encode()|e('html_attr') }}"
    {{ parent() }}
{% endblock %}

{% block input %}
    <div class="{{ form_field_wrapper_classes ?: 'form-select-wrapper' }} {{ field.size }} {{ field.wrapper_classes }}">
        <select name="{{ (scope ~ field.name)|fieldName ~ (field.multiple ? '[]' : '') }}"
                class="{{ form_field_select_classes }} {{ field.classes }} {{ field.size }}"
                {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
                {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
                {% if field.disabled %}disabled="disabled"{% endif %}
                {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                {% if required %}required="required"{% endif %}
                {% if field.multiple in ['on', 'true', 1] %}multiple="multiple"{% endif %}
                {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
                {% if field.tabindex %}tabindex="{{ field.tabindex }}"{% endif %}
                {% if field.form %}form="{{ field.form }}"{% endif %}
                {% if field.autocomplete is defined %}autocomplete="{{ field.autocomplete }}"{% endif %}
                {% if field.key %}
                    data-key-observe="{{ (scope ~ field.name)|fieldName }}"
                {% endif %}
                {% if field.datasets %}
                    {% for datakey, datavalue in field.datasets %}
                        data-{{ datakey }}="{{ datavalue|e('html_attr') }}"
                    {% endfor %}
                {% endif %}
                >
            {% if field.placeholder %}<option value="" disabled selected>{{ field.placeholder|t|raw }}</option>{% endif %}

            {% set options = field.options %}
            {% if field.selectize.create and value %}
              {% set custom_value = field.multiple ? value : { (value): value } %}
              {% set options = options|merge(custom_value|default([]))|array_unique %}
            {% endif %}

            {% set value = value is iterable ? value : value|string %}
            {% for key, item_value in options %}
                {% if item_value is iterable and item_value.value %}
                    {% set akey = field.selectize and field.multiple ? item_value : key %}
                    {% set avalue = item_value.value|t %}
                    <option {{ item_value.disabled ? 'disabled="disabled"' : '' }}
                        {{ item_value.selected ? 'selected="selected"' : '' }}
                        {{ item_value.label    ? 'label=' ~ item_value.label : '' }}
                        value="{{ item_value.akey }}"
                    >
                        {{ avalue|raw }}
                    </option><commit_msg>Fixed select field where option is iterable (#558)<commit_after>{% extends "forms/field.html.twig" %}

{% block global_attributes %}
    data-grav-selectize="{{ (field.selectize is defined ? field.selectize : {})|json_encode()|e('html_attr') }}"
    {{ parent() }}
{% endblock %}

{% block input %}
    <div class="{{ form_field_wrapper_classes ?: 'form-select-wrapper' }} {{ field.size }} {{ field.wrapper_classes }}">
        <select name="{{ (scope ~ field.name)|fieldName ~ (field.multiple ? '[]' : '') }}"
                class="{{ form_field_select_classes }} {{ field.classes }} {{ field.size }}"
                {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
                {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
                {% if field.disabled %}disabled="disabled"{% endif %}
                {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                {% if required %}required="required"{% endif %}
                {% if field.multiple in ['on', 'true', 1] %}multiple="multiple"{% endif %}
                {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
                {% if field.tabindex %}tabindex="{{ field.tabindex }}"{% endif %}
                {% if field.form %}form="{{ field.form }}"{% endif %}
                {% if field.autocomplete is defined %}autocomplete="{{ field.autocomplete }}"{% endif %}
                {% if field.key %}
                    data-key-observe="{{ (scope ~ field.name)|fieldName }}"
                {% endif %}
                {% if field.datasets %}
                    {% for datakey, datavalue in field.datasets %}
                        data-{{ datakey }}="{{ datavalue|e('html_attr') }}"
                    {% endfor %}
                {% endif %}
                >
            {% if field.placeholder %}<option value="" disabled selected>{{ field.placeholder|t|raw }}</option>{% endif %}

            {% set options = field.options %}
            {% if field.selectize.create and value %}
              {% set custom_value = field.multiple ? value : { (value): value } %}
              {% set options = options|merge(custom_value|default([]))|array_unique %}
            {% endif %}

            {% set value = value is iterable ? value : value|string %}
            {% for key, item_value in options %}
                {% if item_value is iterable and item_value.value %}
                    {% set akey = field.selectize and field.multiple ? item_value : key %}
                    {% set avalue = item_value.value|t %}
                    <option {{ item_value.disabled ? 'disabled="disabled"' : '' }}
                        {{ item_value.selected or key == value ? 'selected="selected"' : '' }}
                        {{ item_value.label    ? 'label=' ~ item_value.label : '' }}
                        value="{{ akey }}"
                    >
                        {{ avalue|raw }}
                    </option>
{'fraction_non_alphanumeric': 0.17160534028003907, 'fraction_numerical': 0.001465320742429176, 'mean_word_length': 1.8745905474964903, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2642893', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1560, 'n_words': 375}