{% extends "forms/field.html.twig" %}

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

{% block input %}
    <div class="form-input-wrapper {{ field.size }}">
        <select
                value="{{ value|raw|join(', ') }}"
                name="{{ (scope ~ field.name)|fieldName }}"
                data-select-observe
                {% block input_attributes %}
                    {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
                    {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
                    {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
                    {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
                    {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
                    {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                    {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                    {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
                    {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
                    {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
                    {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %}
                    {% if field.validate.message %}title="{{ field.validate.message|e|t }}"
                    {% elseif field.title is defined %}title="{{ field.title|e|t }}" {% endif %}
                {% endblock %}
        >
            {% if field.placeholder %}<option value="" disabled selected>{% if grav.twig.twig.filters['tu'] is defined %}{{ field.placeholder|tu|raw }}{% else %}{{ field.placeholder|t|raw }}{% endif %}</option>{% endif %}

            {% if value is defined %}
                <option selected="selected" value="{{ value }}">{{ value }}</option>
            {% endif %}
        </select>

        {% if field.default %}
            <div><p class="notice warning">It is advised not to use a <strong>default</strong> option with the selectunique field. Currently default value set to `{{ field.default }}`</p></div>
        {% endif %}
    </div>
{% endblock %}