КОНТРОЛЫ/select.md


Исходный код

Twig код

{# На случай, если выбранного значения нет в списке #}
{% if selected %}
  {% set selected_temp = selected %}
  {% set selected = false %}
  {% set selected_isset = false %}

  {% for v in items %}
    {% set value = v.id %}
    {% if v.id is not defined %}
      {% set value = v.option %}
    {% endif %}

    {% if value == selected_temp %}
      {% set selected = selected_temp %}
      {% set selected_isset = true %}
    {% endif %}
  {% endfor %}
{% endif %}
{# выбранного значения нет #}

{% if not control_class_name %}
  {% set control_class_name = 'control--select' %}
{% endif %}

<div class="{{ control_class_name }} {{ class_name }} {% if theme %}control--select--{{ theme }}{% endif %}" {% if save_overflow %} data-save-overflow="true" {% endif %} {{ additional_data|raw }}>
  <ul class="custom-scroll control--select--list {{ dropdown_auto_width ? 'control--select--list--auto-width' : '' }} {{ dropdown_class_name }}">
    {% set selected_value = selected %}
    {% set selected_option = '' %}
    {% set selected_raw = false %}
    {% set selected_bg_color = '' %}

    {% for v in items %}
      {% set option = v.option %}
      {% set is_selected = false %}

      {% set value = v.id %}
      {% if v.id is not defined %}
        {% set value = option %}
      {% endif %}

      {% if selected_value and (value == selected) %}
        {% set selected_value = value %}
        {% set selected_option = option %}
        {% set selected_raw = v.should_be_raw %}
        {% set is_selected = true %}
        {% if v.bg_color %}
          {% set selected_bg_color = v.bg_color %}
        {% endif %}
      {% elseif not selected_value and loop.first %}
        {% set selected_value = value %}
        {% set selected_option = option %}
        {% set selected_raw = v.should_be_raw %}
        {% set is_selected = true %}
        {% if v.bg_color %}
          {% set selected_bg_color = v.bg_color %}
        {% endif %}
      {% endif %}
      <li data-value="{{ value }}" {% if v.disabled %} data-disabled="disabled" {% endif %} data-color="" class="control--select--list--item {% if is_selected %}control--select--list--item-selected{% endif %} {% if default is defined and v.id == default %}control--select--list--item-default{% endif %} {% if v.bg_color %}control--select--list--item-colored{% endif %} {{v.class_name}}" {% if v.bg_color %} data-bg-color="{{v.bg_color}}" {% endif %} style="{% if v.bg_color %}background-color:{{v.bg_color}};{% endif %}{% if v.text_color %}color:{{v.text_color}};{% endif %}" {{ v.additional_data|raw }}>
        <span class="control--select--list--item-inner" {% if not no_titles %} title="{{option|striptags}}" {% endif %}>
          {% if v.should_be_raw %}
            {{ option|raw }}
          {% else %}
            {{ option }}
          {% endif %}
        </span>
      </li>
    {% endfor %}
  </ul>

  <button class="control--select--button {{button_class_name}} {% if skip_before_empty_data_value %}control--select--button-skip-before-empty-data-value{% endif %} {% if selected_bg_color %}control--select--button-colored{% endif %} {% if referral_form is defined %}pipeline-select__button-create-new-field{% endif %}" tabindex="{{tab_index}}" type="button" data-value="{{selected_value}}" {% if disabled %} disabled="Y" {% endif %} {% if selected_before is defined %} data-before="{{selected_before}}" {% endif %} {% if selected_after is defined %} data-after="{{selected_after}}" {% endif %} {% if selected_bg_color %} style="background: {{selected_bg_color}}" {% endif %}>
    <span class="control--select--button-inner">
      {% if selected_raw %}
        {{ selected_option|raw }}
      {% else %}
        {{ selected_option }}
      {% endif %}
    </span>
  </button>
  <input type="hidden" class="control--select--input {{ input_special_class }}" {% if id %}id="{{id}}"{% endif %} name="{{name}}" value="{{selected_value}}" data-prev-value="{{selected_value}}" {% if form %} form="{{ form }}" {% endif %}>
</div>

Ссылка на вики репозиторий