diff --git a/django_forms_bootstrap/templates/bootstrap/_field_errors.html b/django_forms_bootstrap/templates/bootstrap/_field_errors.html index 85ffdc0..5203117 100644 --- a/django_forms_bootstrap/templates/bootstrap/_field_errors.html +++ b/django_forms_bootstrap/templates/bootstrap/_field_errors.html @@ -1,3 +1,3 @@ {% for error in field.errors %} - {{ error }} +
{{ error }}
+{{ field.help_text|safe }}
+ {{ field.help_text|safe }} {% endif %} \ No newline at end of file diff --git a/django_forms_bootstrap/templatetags/bootstrap_tags.py b/django_forms_bootstrap/templatetags/bootstrap_tags.py index d4325d3..ec16811 100644 --- a/django_forms_bootstrap/templatetags/bootstrap_tags.py +++ b/django_forms_bootstrap/templatetags/bootstrap_tags.py @@ -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