Skip to content

Commit

Permalink
Add class representing a Div
Browse files Browse the repository at this point in the history
Just a blank div that can be customized with classes
and stuff.
replaces crispyforms Div.
  • Loading branch information
stveit committed Nov 13, 2024
1 parent 3f0faab commit 64ec82a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/nav/web/crispyforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,18 @@ class and template definitions.
form_id=form_id,
form_class=form_class,
)


class FormDiv:
"""A class representing a div in a form layout.
:param fields: A list of fields to include in the div.
:param css_classes: Additional CSS classes to apply to the div.
"""

def __init__(
self, fields: Optional[list] = None, css_classes: Optional[str] = None
):
self.fields = fields
self.css_classes = css_classes
self.template = 'custom_crispy_templates/form_div.html'
11 changes: 11 additions & 0 deletions python/nav/web/templates/custom_crispy_templates/form_div.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{# NB! This form div can only render fields that are supported by custom_crispy_templates/_form_field.html #}

<div
{% if field.css_classes %} class="{{ field.css_classes }}" {% endif %}
>
{% block formdiv_content %}
{% for field in field.fields %}
{% include 'custom_crispy_templates/_form_field.html' %}
{% endfor %}
{% endblock %}
</div>

0 comments on commit 64ec82a

Please sign in to comment.