Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bootstrapform/templates/bootstrapform/errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% if errors %}
<div class="alert alert-danger">
<a class="close" data-dismiss="alert">&times;</a>
{% for error in errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
11 changes: 3 additions & 8 deletions bootstrapform/templates/bootstrapform/form.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{% if form.non_field_errors %}
<div class="alert alert-danger">
<a class="close" data-dismiss="alert">&times;</a>
{% for non_field_error in form.non_field_errors %}
{{ non_field_error }}
{% endfor %}
</div>
{% endif %}
{% with errors=form.non_field_errors %}
{% include 'bootstrapform/errors.html' %}
{% endwith %}

{% for field in form.hidden_fields %}
{{ field }}
Expand Down
7 changes: 4 additions & 3 deletions bootstrapform/templatetags/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ Usage
# or use with individual field
{{ form.<field name>|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' }}

Expand Down