diff --git a/python/nav/web/crispyforms.py b/python/nav/web/crispyforms.py index de27b498d1..ede43e25fc 100644 --- a/python/nav/web/crispyforms.py +++ b/python/nav/web/crispyforms.py @@ -27,6 +27,17 @@ class CheckBox(Field): template = 'custom_crispy_templates/horizontal_checkbox.html' +class FormCheckBox: + """Checkbox suited for the NAV layout + + :param field: A field to render as a checkbox field. + """ + + def __init__(self, field): + self.field = field + self.input_type = 'checkbox' + + class HelpField(Field): """Field that displays an icon with tooltip as helptext""" diff --git a/python/nav/web/templates/custom_crispy_templates/_form_field.html b/python/nav/web/templates/custom_crispy_templates/_form_field.html index 16e10cddb7..cbcd627dee 100644 --- a/python/nav/web/templates/custom_crispy_templates/_form_field.html +++ b/python/nav/web/templates/custom_crispy_templates/_form_field.html @@ -6,6 +6,8 @@ {% include 'custom_crispy_templates/submit_field.html' with input=field %} {% elif field.input_type == 'helpfield' %} {% include 'custom_crispy_templates/field_helptext_as_icon.html' with field=field.field %} +{% elif field.input_type == 'checkbox' %} + {% include 'custom_crispy_templates/form_checkbox.html' with field=field.field %} {% else %} {% show_field field %} {% endif %} diff --git a/python/nav/web/templates/custom_crispy_templates/form_checkbox.html b/python/nav/web/templates/custom_crispy_templates/form_checkbox.html new file mode 100644 index 0000000000..f5389fa0d5 --- /dev/null +++ b/python/nav/web/templates/custom_crispy_templates/form_checkbox.html @@ -0,0 +1,11 @@ +
+ + {% for error in field.errors %} + + {{ error }} + + {% endfor %} +