From 549e4c57d07a40e0799e63203dfa4803ca2e13b5 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Mon, 11 Nov 2024 09:22:51 +0100 Subject: [PATCH] Add non-crispy checkbox When old checkbox is removed this should prob be renamed to just "CheckBox" --- python/nav/web/crispyforms.py | 11 +++++++++++ .../custom_crispy_templates/_form_field.html | 2 ++ .../custom_crispy_templates/form_checkbox.html | 11 +++++++++++ 3 files changed, 24 insertions(+) create mode 100644 python/nav/web/templates/custom_crispy_templates/form_checkbox.html 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 %} +