Fixes for 'non field' errors in forms

- Fixes issue where non-model fields would not show error text
This commit is contained in:
Oliver Walters 2020-11-27 10:42:01 +11:00
parent aacc7119bd
commit 56f05e2604
2 changed files with 4 additions and 18 deletions

View File

@ -28,6 +28,7 @@ class HelperForm(forms.ModelForm):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_show_errors = True
"""
Create a default 'layout' for this form.
@ -43,11 +44,6 @@ class HelperForm(forms.ModelForm):
valid = super(HelperForm, self).is_valid()
# Check for errors from model validation
# If none, disable crispy form errors
if not self.errors:
self.helper.form_show_errors = False
return valid
def rebuild_layout(self):

View File

@ -1,3 +1,5 @@
{% load i18n %}
<div>
{% if form.pre_form_info %}
<div class='alert alert-info alert-block' role='alert'>
@ -9,18 +11,6 @@
{{ form.pre_form_warning }}
</div>
{% endif %}
{% block non_field_error %}
{% if form.non_field_errors %}
<div class='alert alert-danger alert-block' role='alert'>
<b>Error Submitting Form:</b>
<ul>
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</ul>
</div>
{% endif %}
{% endblock %}
</div>
{% block pre_form_content %}