Skip to content

Commit ac77e6b

Browse files
committed
Fixed a bug that prevented horizontal form classes from being settable in template tags.
1 parent 5c48e02 commit ac77e6b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

bootstrap3/renderers.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def __init__(self, *args, **kwargs):
3131
self.exclude = kwargs.get('exclude', '')
3232
self.set_required = kwargs.get('set_required', True)
3333
self.size = self.parse_size(kwargs.get('size', ''))
34+
self.horizontal_label_class = kwargs.get(
35+
'horizontal_label_class',
36+
get_bootstrap_setting('horizontal_label_class')
37+
)
38+
self.horizontal_field_class = kwargs.get(
39+
'horizontal_field_class',
40+
get_bootstrap_setting('horizontal_field_class')
41+
)
3442

3543
def parse_size(self, size):
3644
size = text_value(size).lower().strip()
@@ -81,6 +89,8 @@ def render_forms(self):
8189
exclude=self.exclude,
8290
set_required=self.set_required,
8391
size=self.size,
92+
horizontal_label_class=self.horizontal_label_class,
93+
horizontal_field_class=self.horizontal_field_class,
8494
))
8595
return '\n'.join(rendered_forms)
8696

@@ -130,6 +140,8 @@ def render_fields(self):
130140
exclude=self.exclude,
131141
set_required=self.set_required,
132142
size=self.size,
143+
horizontal_label_class=self.horizontal_label_class,
144+
horizontal_field_class=self.horizontal_field_class,
133145
))
134146
return '\n'.join(rendered_fields)
135147

@@ -322,7 +334,7 @@ def append_to_field(self, html):
322334
def get_field_class(self):
323335
field_class = self.field_class
324336
if not field_class and self.layout == 'horizontal':
325-
field_class = get_bootstrap_setting('horizontal_field_class')
337+
field_class = self.horizontal_field_class
326338
return field_class
327339

328340
def wrap_field(self, html):
@@ -334,7 +346,7 @@ def wrap_field(self, html):
334346
def get_label_class(self):
335347
label_class = self.label_class
336348
if not label_class and self.layout == 'horizontal':
337-
label_class = get_bootstrap_setting('horizontal_label_class')
349+
label_class = self.horizontal_label_class
338350
label_class = text_value(label_class)
339351
if not self.show_label:
340352
label_class = add_css_class(label_class, 'sr-only')

bootstrap3/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def test_layout_horizontal(self):
190190
res = render_template('{% bootstrap_form form layout="horizontal" %}', form=form)
191191
self.assertIn('col-md-2', res)
192192
self.assertIn('col-md-4', res)
193+
res = render_template('{% bootstrap_form form layout="horizontal" horizontal_label_class="hlabel" horizontal_field_class="hfield" %}', form=form)
194+
self.assertIn('hlabel', res)
195+
self.assertIn('hfield', res)
193196

194197
def test_buttons_tag(self):
195198
form = TestForm()

0 commit comments

Comments
 (0)