diff --git a/app/main/forms.py b/app/main/forms.py
index bd513ba73..eee4082e1 100644
--- a/app/main/forms.py
+++ b/app/main/forms.py
@@ -837,10 +837,7 @@ class RadioFieldWithNoneOption(FieldWithNoneOption, RadioField):
pass
-class NestedRadioField(RadioFieldWithNoneOption):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
-
+class NestedFieldMixin:
def children(self):
# start map with root option as a single child entry
child_map = {None: [option for option in self
@@ -864,6 +861,14 @@ class NestedRadioField(RadioFieldWithNoneOption):
return child_map
+class NestedRadioField(RadioFieldWithNoneOption, NestedFieldMixin):
+ pass
+
+
+class NestedCheckboxesField(SelectMultipleField, NestedFieldMixin):
+ pass
+
+
class HiddenFieldWithNoneOption(FieldWithNoneOption, HiddenField):
pass
diff --git a/app/templates/components/radios.html b/app/templates/components/radios.html
index 351158acb..b7b51f6cd 100644
--- a/app/templates/components/radios.html
+++ b/app/templates/components/radios.html
@@ -1,111 +1,27 @@
-{% macro radios(
- field,
- hint=None,
- disable=[],
- 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 %}
+{% from "components/select-input.html" import select, select_list, select_nested, select_wrapper %}
+
+{% macro radios(field, hint=None, disable=[], option_hints={}, hide_legend=False) %}
+ {{ select(field, hint=None, disable=[], option_hints={}, hide_legend=False, input="radio") }}
{% endmacro %}
-{% macro radio_list(
- options,
- child_map,
- disable=[],
- option_hints={}
-) %}
-
- {% for option in options %}
- {% if child_map[option.data] %}
- {% call radio(option, disable, option_hints, as_list_item=True) %}
- {{ radio_list(child_map[option.data], child_map, disable, option_hints) }}
- {% endcall %}
- {% else %}
- {{ radio(option, disable, option_hints, as_list_item=True) }}
- {% endif %}
- {% endfor %}
-
+{% macro radio_list(options, child_map, disable=[], option_hints={}) %}
+ {{ select_list(options, child_map, disable=[], option_hints={}, input="radio") }}
{% endmacro %}
-{% macro radios_nested(
- field,
- child_map,
- hint=None,
- disable=[],
- option_hints={},
- hide_legend=False
-) %}
- {% call radios_wrapper(
- field, hint, disable, option_hints, hide_legend
- ) %}
-
- {{ radio_list(child_map[None], child_map, disable, option_hints) }}
-
- {% endcall %}
+{% macro radios_nested(field, child_map, hint=None, disable=[], option_hints={}, hide_legend=False) %}
+ {{ select_nested(field, child_map, hint=None, disable=[], option_hints={}, hide_legend=False, input="radio") }}
{% endmacro %}
+
{% macro radios_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False) %}
-
-
-
+ {{ select_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False, input="radio") }}
{% endmacro %}
+
{% macro radio(option, disable=[], option_hints={}, data_target=None, as_list_item=False) %}
- {% if as_list_item %}
-
- {% else %}
-
- {% endif %}
-
-
- {% if caller %}
- {{ caller() }}
- {% endif %}
- {% if as_list_item %}
-
- {% else %}
-
- {% endif %}
+ {{ select_input(option, disable=[], option_hints={}, data_target=None, as_list_item=False, input="radio") }}
{% endmacro %}
diff --git a/app/templates/components/select-input.html b/app/templates/components/select-input.html
new file mode 100644
index 000000000..b3cfbb9e4
--- /dev/null
+++ b/app/templates/components/select-input.html
@@ -0,0 +1,92 @@
+{% macro select(field, hint=None, disable=[], option_hints={}, hide_legend=False, input="radio") %}
+ {% call select_wrapper(
+ field, hint, disable, option_hints, hide_legend
+ ) %}
+ {% for option in field %}
+ {{ select_input(option, disable, option_hints, input=input) }}
+ {% endfor %}
+ {% endcall %}
+{% endmacro %}
+
+
+{% macro select_list(options, child_map, disable=[], option_hints={}, input="radio") %}
+
+ {% for option in options %}
+ {% if child_map[option.data] %}
+ {% call select_input(option, disable, option_hints, as_list_item=True, input=input) %}
+ {{ select_list(child_map[option.data], child_map, disable, option_hints, input=input) }}
+ {% endcall %}
+ {% else %}
+ {{ select_input(option, disable, option_hints, as_list_item=True, input=input) }}
+ {% endif %}
+ {% endfor %}
+
+{% endmacro %}
+
+
+{% macro select_nested(field, child_map, hint=None, disable=[], option_hints={}, hide_legend=False, input="radio") %}
+ {% call select_wrapper(
+ field, hint, disable, option_hints, hide_legend
+ ) %}
+
+ {{ select_list(child_map[None], child_map, disable, option_hints, input=input) }}
+
+ {% endcall %}
+{% endmacro %}
+
+
+{% macro select_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False) %}
+
+
+
+{% endmacro %}
+
+{% macro select_input(option, disable=[], option_hints={}, data_target=None, as_list_item=False, input="radio") %}
+ {% if as_list_item %}
+
+ {% else %}
+
+ {% endif %}
+
+
+ {% if caller %}
+ {{ caller() }}
+ {% endif %}
+ {% if as_list_item %}
+
+ {% else %}
+
+ {% endif %}
+{% endmacro %}