Skip to content

Commit

Permalink
Merge pull request #3000 from Uninett/uncrispyfy/foundation5-field
Browse files Browse the repository at this point in the history
Uncrispyfy foundation5 field
  • Loading branch information
podliashanyk authored Sep 25, 2024
2 parents d54881a + e07a0a0 commit 5d58d78
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
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
@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 %}"
>
{% 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 %}

0 comments on commit 5d58d78

Please sign in to comment.