Skip to content

Commit

Permalink
Add non-crispy checkbox
Browse files Browse the repository at this point in the history
When old checkbox is removed this should prob be
renamed to just "CheckBox"
  • Loading branch information
stveit committed Nov 13, 2024
1 parent 82792c5 commit e9adc63
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/nav/web/crispyforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -189,6 +200,7 @@ class and template definitions.
form_id=form_id,
form_class=form_class,
)
<<<<<<< HEAD


class FormDiv:
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="div_{{ field.auto_id }}" class="ctrlHolder{% if field.errors %} error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
<label for="{{ field.id_for_label }}">
{{ field.label}}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
{{ field }}
</label>
{% for error in field.errors %}
<small id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="errorField">
{{ error }}
</small>
{% endfor %}
</div>

0 comments on commit e9adc63

Please sign in to comment.