Skip to content

Commit 2d99d97

Browse files
committed
Fixes zostera#383.
1 parent 799872a commit 2d99d97

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

bootstrap3/renderers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
ReadOnlyPasswordHashWidget = None
99

1010
from django.forms import (
11-
TextInput, DateInput, FileInput, CheckboxInput, MultiWidget,
12-
ClearableFileInput, Select, RadioSelect, CheckboxSelectMultiple
11+
TextInput, DateInput, FileInput, CheckboxInput, MultiWidget, ClearableFileInput,
12+
Select, RadioSelect, CheckboxSelectMultiple, NumberInput, EmailInput, URLInput
1313
)
1414
# Django 1.9 moved SelectDateWidget to django.forms.widget from
1515
# django.forms.extras. Django 2.0 will remove the old import location.
@@ -443,7 +443,8 @@ def wrap_widget(self, html):
443443
return html
444444

445445
def make_input_group(self, html):
446-
if (self.addon_before or self.addon_after) and isinstance(self.widget, (TextInput, DateInput, Select)):
446+
if (self.addon_before or self.addon_after) and isinstance(
447+
self.widget, (TextInput, NumberInput, EmailInput, URLInput, DateInput, Select)):
447448
before = '<span class="{input_class}">{addon}</span>'.format(
448449
input_class=self.addon_before_class, addon=self.addon_before) if self.addon_before else ''
449450
after = '<span class="{input_class}">{addon}</span>'.format(

bootstrap3/tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class TestForm(forms.Form):
8888
widget=forms.CheckboxSelectMultiple,
8989
help_text='Check as many as you like.',
9090
)
91+
number = forms.FloatField()
92+
url = forms.URLField()
9193
addon = forms.CharField(
9294
widget=forms.TextInput(attrs={'addon_before': 'before', 'addon_after': 'after'}),
9395
)
@@ -715,3 +717,42 @@ class ShowPlaceholderTest(TestCase):
715717
def test_placeholder_set_from_label(self):
716718
res = render_form_field('sender')
717719
self.assertIn('placeholder="Sender © unicode"', res)
720+
721+
722+
class ShowAddonsTest(TestCase):
723+
724+
def test_show_addons_textinput(self):
725+
res = render_template_with_form('{% bootstrap_field form.subject addon_before="$" addon_after=".00" %}')
726+
self.assertIn('class="input-group"', res)
727+
self.assertIn('class="input-group-addon">$', res)
728+
self.assertIn('class="input-group-addon">.00', res)
729+
730+
def test_show_addons_select(self):
731+
res = render_template_with_form('{% bootstrap_field form.select1 addon_before="$" addon_after=".00" %}')
732+
self.assertIn('class="input-group"', res)
733+
self.assertIn('class="input-group-addon">$', res)
734+
self.assertIn('class="input-group-addon">.00', res)
735+
736+
def test_show_addons_dateinput(self):
737+
res = render_template_with_form('{% bootstrap_field form.date addon_before="$" addon_after=".00" %}')
738+
self.assertIn('class="input-group"', res)
739+
self.assertIn('class="input-group-addon">$', res)
740+
self.assertIn('class="input-group-addon">.00', res)
741+
742+
def test_show_addons_email(self):
743+
res = render_template_with_form('{% bootstrap_field form.sender addon_before="$" addon_after=".00" %}')
744+
self.assertIn('class="input-group"', res)
745+
self.assertIn('class="input-group-addon">$', res)
746+
self.assertIn('class="input-group-addon">.00', res)
747+
748+
def test_show_addons_number(self):
749+
res = render_template_with_form('{% bootstrap_field form.number addon_before="$" addon_after=".00" %}')
750+
self.assertIn('class="input-group"', res)
751+
self.assertIn('class="input-group-addon">$', res)
752+
self.assertIn('class="input-group-addon">.00', res)
753+
754+
def test_show_addons_url(self):
755+
res = render_template_with_form('{% bootstrap_field form.url addon_before="$" addon_after=".00" %}')
756+
self.assertIn('class="input-group"', res)
757+
self.assertIn('class="input-group-addon">$', res)
758+
self.assertIn('class="input-group-addon">.00', res)

0 commit comments

Comments
 (0)