Skip to content

Commit

Permalink
Update checkbox(es) to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood committed Oct 23, 2020
1 parent 5446fb4 commit 4fbc930
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 11 additions & 5 deletions templates/forms/fields/checkbox/checkbox.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@
{% endblock %}

{% block input %}
{% set id = field.id|default(field.name) ~ '-' ~ key %}
{% set id = field.id|default(field.name)|hyphenize %}
<div class="{{ form_field_wrapper_classes ?: 'form-input-wrapper' }} {{ field.size }} {{ field.wrapper_classes }}">
<label class="{{ form_field_checkbox_classes }}" for="{{ id|e }}">
<input
{# required attribute structures #}
name="{{ (scope ~ field.name)|fieldName }}"
value="{{ value|join(', ') }}"
value="{{ field.value ?? '1' }}"
type="checkbox"
{% if value == true %} checked="checked" {% endif %}
{% if value == field.value ?? '1' %} checked="checked" {% endif %}

{# input attribute structures #}
{% block input_attributes %}
id="{{ id|e }}"
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
class="{{ form_field_checkbox_classes }} {{ field.classes }}"
{% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if required %}required="required"{% endif %}
{% if field.tabindex %}tabindex="{{ field.tabindex }}"{% endif %}
{% endblock %}
/>
<i class="form-icon"></i>
{{ field.label|t|e }} {{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
{% if field.markdown %}
{{ field.label|t|markdown(false) }}
{% else %}
{{ field.label|t|e }}
{% endif %}
{{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
</label>
</div>
{% endblock %}
5 changes: 2 additions & 3 deletions templates/forms/fields/checkboxes/checkboxes.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% block input %}
{% for key, text in field.options %}

{% set id = field.id|default(field.name) ~ '-' ~ key %}
{% set id = field.id|default(field.name)|hyphenize ~ '-' ~ key %}
{% set name = field.use == 'keys' ? key : id %}
{% set val = field.use == 'keys' ? '1' : key %}
{% set checked = (field.use == 'keys' ? value[key] : key in value) %}
Expand All @@ -27,10 +27,9 @@
id="{{ id|e }}"
value="{{ val|e }}"
name="{{ (scope ~ field.name)|fieldName ~ '[' ~ name ~ ']' }}"
class="{{ form_field_checkbox_classes }} {{ field.classes }}"
{% if checked %}checked="checked"{% endif %}
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}

>
<i class="form-icon"></i>
{% if help %}
Expand Down

0 comments on commit 4fbc930

Please sign in to comment.