Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class representing a Div #3169

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading