Skip to content

Commit f49b0de

Browse files
committed
tweak for Bootstrap v4.0.0-beta
1 parent 75ed135 commit f49b0de

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% for error in field.errors %}
2-
<span id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="error-msg">{{ error }}</span>
2+
<div id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="invalid-feedback">{{ error }}</div>
33
{% endfor %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% for error in field.errors %}
2-
<p id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="help-block">{{ error }}</p>
2+
<div id="error_{{ field.auto_id }}_{{ forloop.counter }}" class="invalid-feedback">{{ error }}</div>
33
{% endfor %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% if field.help_text %}
2-
<p class="help-block">{{ field.help_text|safe }}</p>
2+
<small class="form-text text-muted">{{ field.help_text|safe }}</small>
33
{% endif %}

django_forms_bootstrap/templatetags/bootstrap_tags.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414

1515

1616
def _preprocess_fields(form):
17+
invalid_form = True if len(form.errors) > 0 else False
18+
1719
for field in form.fields:
1820
name = form.fields[field].widget.__class__.__name__.lower()
1921
if not name.startswith("radio") and not name.startswith("checkbox"):
22+
23+
if invalid_form:
24+
if field in form.errors:
25+
validation_state = ' is-invalid'
26+
else:
27+
validation_state = ' is-valid'
28+
else:
29+
validation_state = ''
30+
2031
try:
21-
form.fields[field].widget.attrs["class"] += " form-control"
32+
form.fields[field].widget.attrs["class"] += ' form-control' + validation_state
2233
except KeyError:
23-
form.fields[field].widget.attrs["class"] = " form-control"
34+
form.fields[field].widget.attrs["class"] = ' form-control' + validation_state
2435
return form
2536

2637

0 commit comments

Comments
 (0)