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

Uncrispyfy foundation5 field #3000

Merged
merged 4 commits into from
Sep 25, 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
12 changes: 12 additions & 0 deletions python/nav/django/templatetags/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Template filters for forms"""

from django import forms, template

register = template.Library()


# Copied from
# https://github.com/django-crispy-forms/django-crispy-forms/blob/1.8.1/crispy_forms/templatetags/crispy_forms_field.py
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so trivial that I wouldn't bother with citing a source...

@register.filter
def is_checkbox(field):
return isinstance(field.field.widget, forms.CheckboxInput)
32 changes: 15 additions & 17 deletions python/nav/web/templates/foundation-5/field.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{% load crispy_forms_field %}
{% load forms %}

{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}"
class="ctrlHolder
{% if field.errors and form_show_errors %} error{% endif %}
{% if field|is_checkbox %} checkbox{% endif %}
{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
class="ctrlHolder{% if field.errors %} error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"
>
hmpf marked this conversation as resolved.
Show resolved Hide resolved
{% spaceless %}

{% if field.label %}
{% if field|is_checkbox %}
{% crispy_field field %}
{{ field }}
{% endif %}

<label for="{{ field.id_for_label }}"
{% if field.field.required %}class="requiredField"{% endif %}>
{{ field.label|safe }}{% if field.field.required %}
<span class="asteriskField">*</span>{% endif %}
{{ field.label|safe }}
{% if field.field.required %}
<span class="asteriskField">*</span>
{% endif %}
{% if field.help_text %}
&nbsp;<i id="hint_{{ field.auto_id }}" class="fa fa-info-circle right"
data-tooltip title="
Expand All @@ -30,17 +30,15 @@
{% endif %}

{% if not field|is_checkbox %}
{% crispy_field field %}
{{ field }}
{% endif %}

{% if form_show_errors %}
{% for error in field.errors %}
<small id="error_{{ forloop.counter }}_{{ field.auto_id }}"
class="error">
{{ error }}
</small>
{% endfor %}
{% endif %}
{% for error in field.errors %}
<small id="error_{{ forloop.counter }}_{{ field.auto_id }}"
class="error">
{{ error }}
</small>
{% endfor %}

{% endspaceless %}
</div>
Expand Down
17 changes: 1 addition & 16 deletions python/nav/web/templates/seeddb/_form_fields.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
{% for field in form %}
<div id="div_id_{{ field.name }}"
class="ctrlHolder{% if field.errors %} error{% endif %}"
>
<label for="id_{{ field.name }}"
class="{% if field.field.required %}requiredField{% endif %}"
>
{{ field.label.title }}
{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{{ field }}
{% for error in field.errors %}
<small id="error_{{ forloop.counter }}_id_{{ field.name }}" class="error">
{{ error }}
</small>
{% endfor %}
</div>
{% include "foundation-5/field.html" %}
{% endfor %}
Loading