templates/includes/form_elements/select.html.twig line 1

Open in your IDE?
  1. {% set id = id|default('select-id') %}
  2. {% set name = name|default('select') %}
  3. {% set label = label|default('Select label') %}
  4. {% set options = options|default([
  5.     {
  6.         "label": "",
  7.         "value": "",
  8.         "selected": true,
  9.         "disabled": true
  10.     }, {
  11.         label: 'Option 1',
  12.         value: '1'
  13.     }, {
  14.         label: 'Option 2',
  15.         value: '2'
  16.     }]) %}
  17. {% extends "includes/form_elements/form-control.html.twig" %}
  18. {% block input %}
  19.     <select class="form-select form-control {{ (errors|length > 0) ? 'is-invalid' : '' }} {{ attribute(classNames, 'input') }}"
  20.     {% for key, value in inputAttributes|default([]) %}
  21.         {{ key }}="{{ value }}"
  22.     {% endfor %}
  23.     >
  24.     {% for option in options %}
  25.         {% set optionClassName = option.className|default(option.class|default('')) %}
  26.         <option class="{{ optionClassName }}" value="{{ option.value|default('') }}"
  27.             {{ option.selected|default(false) ? 'selected' : null }}
  28.             {{ option.disabled|default(false) ? 'disabled' : null }}
  29.         >
  30.             {{ option.label }}
  31.         </option>
  32.     {% endfor %}
  33.     </select>
  34. {% endblock %}