diff --git a/bootstrapform/templates/bootstrapform/errors.html b/bootstrapform/templates/bootstrapform/errors.html new file mode 100644 index 0000000..ae1f4af --- /dev/null +++ b/bootstrapform/templates/bootstrapform/errors.html @@ -0,0 +1,8 @@ +{% if errors %} +
+ × + {% for error in errors %} + {{ error }} + {% endfor %} +
+{% endif %} diff --git a/bootstrapform/templates/bootstrapform/form.html b/bootstrapform/templates/bootstrapform/form.html index 37661ae..45201f3 100644 --- a/bootstrapform/templates/bootstrapform/form.html +++ b/bootstrapform/templates/bootstrapform/form.html @@ -1,11 +1,6 @@ -{% if form.non_field_errors %} -
- × - {% for non_field_error in form.non_field_errors %} - {{ non_field_error }} - {% endfor %} -
-{% endif %} +{% with errors=form.non_field_errors %} + {% include 'bootstrapform/errors.html' %} +{% endwith %} {% for field in form.hidden_fields %} {{ field }} diff --git a/bootstrapform/templatetags/bootstrap.py b/bootstrapform/templatetags/bootstrap.py index 8c36c18..f4053ef 100644 --- a/bootstrapform/templatetags/bootstrap.py +++ b/bootstrapform/templatetags/bootstrap.py @@ -59,12 +59,13 @@ def add_input_classes(field): def render(element, markup_classes): - element_type = element.__class__.__name__.lower() - - if element_type == 'boundfield': + if isinstance(element, forms.forms.BoundField): add_input_classes(element) template = get_template("bootstrapform/field.html") context = Context({'field': element, 'classes': markup_classes}) + elif isinstance(element, forms.forms.ErrorList): + template = get_template("bootstrapform/errors.html") + context = Context({'errors': element}) else: has_management = getattr(element, 'management_form', None) if has_management: diff --git a/docs/install.rst b/docs/install.rst index 0b62106..14eb689 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -52,9 +52,12 @@ Usage # or use with individual field {{ form.|bootstrap }} - To output individual fields + # in this case you have to manually include non field errors: + {{ form.non_field_errors|bootstrap }} + # For horizontal forms {{ form|bootstrap_horizontal }} - + # Or with custom size (default is 'col-lg-2 col-sm-2') {{ form|bootstrap_horizontal:'col-lg-4' }}