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


Исходный код

Twig код

<div class="control-chained-list js-control-chained-list {{ class_name }}">
  {#
    эта переменная отвечает за то, показывать ли
    инпут следующего списка

    первый элемент нам в любом случае надо показать
  #}
  {% set last_list_has_value = true %}

  {% for list in lists %}
    {% set hidden = not values[list.catalog_id] and not last_list_has_value %}
    {% set suggest_class_name = 'control-chained-list__suggest' ~  (hidden ? ' hidden' : '') %}

    {% if not hidden and not values[list.catalog_id].value %}
      {% set suggest_class_name = suggest_class_name ~ ' control-chained-list__suggest_empty' %}
    {% endif %}

    {% if loop.first %}
      {% set suggest_class_name = suggest_class_name ~ ' control-chained-list__suggest_first' %}
    {% endif %}

    {% if loop.last %}
      {% set suggest_class_name = suggest_class_name ~ ' control-chained-list__suggest_last' %}
    {% endif %}

    <input type="hidden" name="{{ name ~ '[' ~ list.catalog_id ~ ']' }}" value="{{ values[list.catalog_id].value }}" class="js-control-changed-list-chain-value {{ value_input_class_name|default('')}} " data-catalog-id="{{ list.catalog_id }}">

    {% include "interface/controls/suggest.twig" with {
      class_name: suggest_class_name,
      input_class_name: input_class_name|default('') ~ ' js-form-changes-skip text-input-visible-placeholder',
      placeholder: list.title,
      additional_data: 'data-catalog-id="' ~ list.catalog_id ~ '" data-parent-element-id="' ~ (last_list_has_value > 0 ? last_list_has_value : '') ~ '" data-placeholder="' ~ list.title ~ '"',
      value: values[list.catalog_id].name,
      disabled: disabled
    } only %}

    {% set last_list_has_value = values[list.catalog_id].value %}
  {% endfor %}

  <script type="application/json">
    {{ lists|json_encode|raw }}
  </script>
</div>

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