templates/Layout/forms/select.html.twig line 1

Open in your IDE?
  1. {% set container_class = container_class ?? null %}
  2. {% set class = class ?? '' %}
  3. {% set label = label ?? null %}
  4. {% set label_class = label_class ?? false %}
  5. {% set form = formAttr ?? false %}
  6. {% set formAttr = formAttr ?? false %}
  7. {% set active_option = active_option ?? null %}
  8. {% set attributes = attributes ?? {} %}
  9. {% set noOptional = noOptional ?? false %}
  10. {% set no_label = no_label ?? false %}
  11. {% set name = name ?? false %}
  12. {% set required = required ?? false %}
  13. {% set id = id ?? null %}
  14. {% if not name and useLabelAsInputName ?? false %}
  15.     {% set name = label %}
  16. {% endif %}
  17. {% if container_class %}
  18. <div class="{{ container_class }}">
  19. {% endif %}
  20.     {% if field is defined and field is not null %}
  21.         {% if not no_label %}{{ form_label(field, label, {'label_attr': {'class': label_class},'noOptional' : noOptional}) }}{% endif %}
  22.         {% set attributes = attributes|merge(field.vars.attr)|merge({'class': class ~ ' ' ~ (field.vars.attr.class ?? '')}) %}
  23.         {% if formAttr %}
  24.             {% set attributes = attributes|merge({'form': formAttr}) %}
  25.         {% endif %}
  26.         {{ form_widget(field, {'attr': attributes, 'id': id ?? field.vars.id}) }}
  27.         {{ form_errors(field) }}
  28.     {% else %}
  29.         {% if label %}
  30.             <label for="{{ id }}" class="{{ label_class }}">{{ label }}</label>
  31.         {% endif %}
  32.         <select
  33.             class="{{ class }}"
  34.             id="{{ id }}"
  35.             name = "{{ name }}"
  36.             {% if form %}
  37.             form={{ form.id ? form.id : form }}
  38.             {% endif %}
  39.             {% if required %}
  40.                 required
  41.             {% endif %}
  42.         >
  43.             {% for option in options %}
  44.                 {% if not option.value ?? false and useRadioLabelAsValue ?? false %}
  45.                     {% set option = option|merge({value:option.label}) %}
  46.                 {% endif %}
  47.                 <option
  48.                     value="{{ option.value }}"
  49.                     {% if option.toggle_id is defined %}data-toggle-id="{{ option.toggle_id }}"{% endif %}
  50.                     {% if active_option == option.value %}selected{% endif %}
  51.                 >{{ option.label }}</option>
  52.             {% endfor %}
  53.         </select>
  54.     {% endif %}
  55. {% if container_class %}
  56. </div>
  57. {% endif %}