Skip to content

Commit

Permalink
Merge pull request #406 from mkoistinen/feature/errors_type_support
Browse files Browse the repository at this point in the history
Satisfies #380: Adds ‘errors_types’ support in bootstrap_form tag
  • Loading branch information
dyve committed Jul 11, 2017
2 parents 66ca85f + 33bc62f commit 2767860
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Contributors
* Jordan Starcher <jstarcher@gmail.com>
* Juan Carlos <juancarlospaco@gmail.com>
* Markus Holtermann <info@markusholtermann.eu>
* Martin Koistinen <mkoistinen@gmail.com>
* Nick S <nsmith448@gmail.com>
* Owais Lone <loneowais@gmail.com>
* pmav99 <pmav99@users.noreply.github.com>
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Development (in progress)
+++++++++++++++++++++++++

* Renamed requirements-dev.txt back to requirements.txt because that suits ReadTheDocs better
* Added 'errors_type' support on bootstrap3_form (thanks @mkoistinen)


8.2.3 (2017-05-05)
Expand Down
5 changes: 3 additions & 2 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(self, form, *args, **kwargs):
if DBS3_SET_REQUIRED_SET_DISABLED and self.form.empty_permitted:
self.set_required = False

self.errors_type = kwargs.get('errors_type', 'all')
self.error_css_class = kwargs.get('error_css_class', None)
self.required_css_class = kwargs.get('required_css_class', None)
self.bound_css_class = kwargs.get('bound_css_class', None)
Expand Down Expand Up @@ -202,7 +203,7 @@ def get_fields_errors(self):
return form_errors

def render_errors(self, type='all'):
form_errors = None
form_errors = []
if type == 'all':
form_errors = self.get_fields_errors() + self.form.non_field_errors()
elif type == 'fields':
Expand All @@ -224,7 +225,7 @@ def render_errors(self, type='all'):
return ''

def _render(self):
return self.render_errors() + self.render_fields()
return self.render_errors(self.errors_type) + self.render_fields()


class FieldRenderer(BaseRenderer):
Expand Down
7 changes: 7 additions & 0 deletions bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def bootstrap_form(*args, **kwargs):
A list of field names (comma separated) that should not be rendered
E.g. exclude=subject,bcc
errors_type
This controls the types of errors that are rendered above the form.
Choices are: "all", "fields", "non_fields" or "none". This will not
affect the display of errors on the fields themselves.
Default is "all".
See bootstrap_field_ for other arguments
**Usage**::
Expand Down

0 comments on commit 2767860

Please sign in to comment.