{%- set options = options ?? [] %} {%- set values = values ?? [] -%} {%- set showAllOption = showAllOption ?? false %} {%- if showAllOption %} {%- set allLabel = allLabel ?? "All"|t('app') %} {%- set allValue = allValue ?? '*' %} {%- set allChecked = (values == allValue) %} {%- endif %} {% set containerAttributes = { class: ['checkbox-select']|merge((class ?? [])|explodeClass), }|merge(containerAttributes ?? [], recursive=true) %} {%- if block('attr') is defined %} {%- set containerAttributes = containerAttributes|merge(('
')|parseAttr, recursive=true) %} {% endif %} {% tag 'fieldset' with containerAttributes %} {%- if showAllOption %}
{% include "_includes/forms/checkbox" with { instructionsId: instructionsId ?? false, class: 'all', label: raw("#{allLabel}"), name: name ?? null, value: allValue, checked: allChecked, autofocus: (autofocus ?? false) and not craft.app.request.isMobileBrowser(true), } only %}
{%- endif %} {%- for key, option in options %} {%- if option is not iterable %} {%- set option = {label: option, value: key} %} {%- endif %} {% if not showAllOption or option.value is not defined or option.value != allValue %}
{% include "_includes/forms/checkbox" with { name: (name ?? false) ? "#{name}[]" : null, checked: ((showAllOption and allChecked) or (option.value is defined and option.value in values)), disabled: (showAllOption and allChecked) }|merge(option) only %}
{% endif %} {% endfor %} {% endtag %}