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 feature to tell which fieldset tab(s) has the validation error #507

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions jazzmin/templates/jazzmin/includes/horizontal_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{% get_sections adminform inline_admin_formsets as forms %}

{% block tabs %}
<ul class="nav nav-tabs mb-3" role="tablist" id="jazzy-tabs">
{% for fieldset in forms %}
<li class="nav-item">
<a class="nav-link{% if forloop.first %} active{% endif %}" data-toggle="pill" role="tab" aria-controls="{{ fieldset.name|default:general_tab|unicode_slugify }}-tab" aria-selected="{% if forloop.first %}true{% else %}false{% endif %}" href="#{{ fieldset.name|default:general_tab|unicode_slugify }}-tab">
{{ fieldset.name|default:general_tab }}
</a>
</li>
{% endfor %}
</ul>
<ul class="nav nav-tabs mb-3" role="tablist" id="jazzy-tabs">
{% for fieldset in forms %}
<li class="nav-item">
<a class="nav-link{% if forloop.first %} active{% endif %}{% if fieldset|has_error %} text-danger{% endif %}" data-toggle="pill" role="tab" aria-controls="{{ fieldset.name|default:general_tab|unicode_slugify }}-tab" aria-selected="{% if forloop.first %}true{% else %}false{% endif %}" href="#{{ fieldset.name|default:general_tab|unicode_slugify }}-tab">
{{ fieldset.name|default:general_tab }}{% if fieldset|has_error %}*{% endif %}
</a>
</li>
{% endfor %}
</ul>
{% endblock tabs %}

<div class="tab-content">
Expand Down
10 changes: 10 additions & 0 deletions jazzmin/templatetags/jazzmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,13 @@ def style_bold_first_word(message: str) -> SafeText:
@register.filter
def unicode_slugify(message: str) -> str:
return slugify(message, allow_unicode=True)


@register.filter(name='has_error')
def has_error(fieldset):
if hasattr(fieldset, 'form'):
return not set(fieldset.form.errors.keys()).isdisjoint(set(fieldset.fields))
elif hasattr(fieldset, 'formset'):
return any(fieldset.formset.errors)

return True
Loading