Refactor radios for reuse

This commit splits up the radio buttons macro into a couple of different
macros which can be used independently of each other.

This makes this code easier to reuse when implementing custom radio
controls.
This commit is contained in:
Chris Hill-Scott
2018-06-12 13:17:45 +01:00
parent 39bb0ecbf7
commit d952b5ca3c

View File

@@ -5,9 +5,19 @@
option_hints={},
hide_legend=False
) %}
{% call radios_wrapper(
field, hint, disable, option_hints, hide_legend
) %}
{% for option in field %}
{{ radio(option, disable, option_hints) }}
{% endfor %}
{% endcall %}
{% endmacro %}
{% macro radios_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False) %}
<div class="form-group {% if field.errors %} form-group-error{% endif %}">
<fieldset>
<legend class="form-label">
<legend class="{{ 'form-label' if not hide_legend else '' }}">
{% if hide_legend %}<span class="visually-hidden">{% endif %}
{{ field.label.text|safe }}
{% if hide_legend %}</span>{% endif %}
@@ -17,14 +27,11 @@
</span>
{% endif %}
</legend>
{% for option in field %}
{{ radio(option, disable, option_hints) }}
{% endfor %}
{{ caller() }}
</fieldset>
</div>
{% endmacro %}
{% macro radio(option, disable=[], option_hints={}) %}
<div class="multiple-choice">
<input