From e9adc63ef5a34b5ea60b5f68a64e6d6c0b5549a7 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 | 25 +++++++++++++++++++ .../custom_crispy_templates/_form_field.html | 2 ++ .../form_checkbox.html | 11 ++++++++ 3 files changed, 38 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..644a40bd1e 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""" @@ -189,6 +200,7 @@ class and template definitions. form_id=form_id, form_class=form_class, ) +<<<<<<< HEAD class FormDiv: @@ -204,3 +216,16 @@ def __init__( self.fields = fields self.css_classes = css_classes self.template = 'custom_crispy_templates/form_div.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' +======= +>>>>>>> bb22cadc8 (Move FormCheckBox next to CheckBox) 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 %} +