Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for error in field.errors %}
<span id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="error-msg">{{ error }}</span>
<div id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="invalid-feedback">{{ error }}</div>
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for error in field.errors %}
<p id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="help-block">{{ error }}</p>
<div id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="invalid-feedback">{{ error }}</div>
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% if field.help_text %}
<p class="help-block">{{ field.help_text|safe }}</p>
<small class="form-text text-muted">{{ field.help_text|safe }}</small>
{% endif %}
15 changes: 13 additions & 2 deletions django_forms_bootstrap/templatetags/bootstrap_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@


def _preprocess_fields(form):
invalid_form = True if len(form.errors) > 0 else False

for field in form.fields:
name = form.fields[field].widget.__class__.__name__.lower()
if not name.startswith("radio") and not name.startswith("checkbox"):

if invalid_form:
if field in form.errors:
validation_state = ' is-invalid'
else:
validation_state = ' is-valid'
else:
validation_state = ''

try:
form.fields[field].widget.attrs["class"] += " form-control"
form.fields[field].widget.attrs["class"] += ' form-control' + validation_state
except KeyError:
form.fields[field].widget.attrs["class"] = " form-control"
form.fields[field].widget.attrs["class"] = ' form-control' + validation_state
return form


Expand Down