Skip to content

Commit e69508b

Browse files
committed
Merge branch 'release/4.11.0'
2 parents 01cf83a + 5ff9275 commit e69508b

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

HISTORY.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ History
44
-------
55

66

7-
4.9.2 (2014-08-11)
8-
++++++++++++++++++
7+
4.11.0 (2014-08-19)
8+
+++++++++++++++++++
99

10-
* Fixed bug causing problems with setting classes for horizontal forms
10+
* Improved handling and control of form classes for error and success
1111

1212

1313
4.10.1 (2014-08-18)
@@ -22,6 +22,12 @@ History
2222
* Template tag `bootstrap_icon` now supports a `title` parameter
2323

2424

25+
4.9.2 (2014-08-11)
26+
++++++++++++++++++
27+
28+
* Fixed bug causing problems with setting classes for horizontal forms
29+
30+
2531
4.9.1 (2014-08-10)
2632
++++++++++++++++++
2733

bootstrap3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '4.10.1'
3+
__version__ = '4.11.0'

bootstrap3/bootstrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'set_required': True,
2020
'set_placeholder': True,
2121
'required_css_class': '',
22-
'error_css_class': '',
22+
'error_css_class': 'has-error',
23+
'success_css_class': 'has-success',
2324
'formset_renderers': {
2425
'default': 'bootstrap3.renderers.FormsetRenderer',
2526
},

bootstrap3/renderers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(self, field, *args, **kwargs):
201201
# These are set in Django or in the global BOOTSTRAP3 settings, and they can be overwritten in the template
202202
error_css_class = kwargs.get('error_css_class', '')
203203
required_css_class = kwargs.get('required_css_class', '')
204+
bound_css_class = kwargs.get('bound_css_class', '')
204205
if error_css_class:
205206
self.error_css_class = error_css_class
206207
else:
@@ -210,6 +211,11 @@ def __init__(self, field, *args, **kwargs):
210211
else:
211212
self.required_css_class = getattr(field.form, 'required_css_class',
212213
get_bootstrap_setting('required_css_class'))
214+
if bound_css_class:
215+
self.success_css_class = bound_css_class
216+
else:
217+
self.success_css_class = getattr(field.form, 'bound_css_class', get_bootstrap_setting('success_css_class'))
218+
213219
# Handle form.empty_permitted
214220
if self.field.form.empty_permitted:
215221
self.set_required = False
@@ -377,7 +383,7 @@ def get_form_group_class(self):
377383
if self.field_errors:
378384
form_group_class = add_css_class(form_group_class, 'has-error')
379385
elif self.field.form.is_bound:
380-
form_group_class = add_css_class(form_group_class, 'has-success')
386+
form_group_class = add_css_class(form_group_class, self.success_css_class)
381387
if self.layout == 'horizontal':
382388
form_group_class = add_css_class(form_group_class, self.get_size_class(prefix='form-group'))
383389
return form_group_class

bootstrap3/tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ def test_settings_filter(self):
136136
'{% load bootstrap3 %}{% if "javascript_in_head"|bootstrap_setting %}head{% else %}body{% endif %}')
137137
self.assertEqual(res.strip(), 'head')
138138

139+
def test_required_class(self):
140+
form = TestForm()
141+
res = render_template('{% bootstrap_form form %}', form=form)
142+
self.assertIn('bootstrap3-req', res)
143+
144+
def test_error_class(self):
145+
form = TestForm({})
146+
res = render_template('{% bootstrap_form form %}', form=form)
147+
self.assertIn('bootstrap3-err', res)
148+
149+
def test_bound_class(self):
150+
form = TestForm({'sender': 'sender'})
151+
res = render_template('{% bootstrap_form form %}', form=form)
152+
self.assertIn('bootstrap3-bound', res)
153+
139154

140155
class TemplateTest(TestCase):
141156
def test_empty_template(self):

docs/settings.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ The ``BOOTSTRAP3`` dict variable is contains these settings and defaults:
5151
'required_css_class': '',
5252
5353
# Class to indicate error (better to set this in your Django form)
54-
'error_css_class': '',
54+
'error_css_class': 'has-error',
55+
56+
# Class to indicate success, meaning the field has valid input (better to set this in your Django form)
57+
'success_css_class': 'has-success',
5558
5659
# Renderers (only set these if you have studied the source and understand the inner workings)
5760
'formset_renderers':{

testsettings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
BOOTSTRAP3 = {
1313
'javascript_in_head': True,
1414
'required_css_class': 'bootstrap3-req',
15+
'error_css_class': 'bootstrap3-err',
16+
'success_css_class': 'bootstrap3-bound',
1517
}
1618

1719
SECRET_KEY = 'bootstrap3isawesome'

0 commit comments

Comments
 (0)