Skip to content

Commit d219330

Browse files
committed
Use field.id_for_label instead of field.auto_id
This fixes a bug when specifying a custom id for a field and rendering it with the `|bootstrap` filter. When using `field.auto_id` in the label's `for` attribute, this is always set to the default value instead of the custom `id`. Also fix a typo in the tests: file_fied -> file_field
1 parent 629d82d commit d219330

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

bootstrapform/fixtures/basic.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</div>
5555

5656
<div class="form-group">
57-
<label class="control-label " for="id_multiple_checkbox">Multiple checkbox</label>
57+
<label class="control-label " for="id_multiple_checkbox_0">Multiple checkbox</label>
5858
<div class=" multiple-checkbox">
5959
<ul id="id_multiple_checkbox">
6060
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
@@ -65,10 +65,10 @@
6565
</div>
6666

6767
<div class="form-group">
68-
<label class="control-label " for="id_file_fied">File fied</label>
68+
<label class="control-label " for="id_file_field">File field</label>
6969

7070
<div class=" ">
71-
<input id="id_file_fied" name="file_fied" type="file" />
71+
<input id="id_file_field" name="file_field" type="file" />
7272
</div>
7373
</div>
7474

bootstrapform/fixtures/horizontal.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</div>
5757

5858
<div class="form-group">
59-
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_checkbox">Multiple checkbox</label>
59+
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_checkbox_0">Multiple checkbox</label>
6060
<div class=" col-sm-10 col-lg-10 multiple-checkbox">
6161
<ul id="id_multiple_checkbox">
6262
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
@@ -67,10 +67,10 @@
6767
</div>
6868

6969
<div class="form-group">
70-
<label class="control-label col-sm-2 col-lg-2 " for="id_file_fied">File fied</label>
70+
<label class="control-label col-sm-2 col-lg-2 " for="id_file_field">File field</label>
7171

7272
<div class=" col-sm-10 col-lg-10 ">
73-
<input id="id_file_fied" name="file_fied" type="file" />
73+
<input id="id_file_field" name="file_field" type="file" />
7474
</div>
7575
</div>
7676

bootstrapform/templates/bootstrapform/field.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
</div>
4747
{% else %}
4848
{% if field.auto_id %}
49-
<label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class }}{% endif %}" for="{{ field.auto_id }}">{{ field.label }}</label>
49+
<label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class }}{% endif %}"
50+
for="{{ field.id_for_label }}">{{ field.label }}</label>
5051
{% endif %}
5152

5253
<div class="{{ classes.value }} {% if field|is_multiple_checkbox %}multiple-checkbox{% endif %}">

bootstrapform/tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExampleForm(forms.Form):
2828
radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect)
2929
multiple_choice = forms.MultipleChoiceField(choices=CHOICES)
3030
multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple)
31-
file_fied = forms.FileField()
31+
file_field = forms.FileField()
3232
password_field = forms.CharField(widget=forms.PasswordInput)
3333
textarea = forms.CharField(widget=forms.Textarea)
3434
boolean_field = forms.BooleanField()

example/app/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ExampleForm(forms.Form):
1212
radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect)
1313
multiple_choice = forms.MultipleChoiceField(choices=CHOICES)
1414
multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple)
15-
file_fied = forms.FileField()
15+
file_field = forms.FileField()
1616
password_field = forms.CharField(widget=forms.PasswordInput)
1717
textarea = forms.CharField(widget=forms.Textarea)
1818
boolean_field = forms.BooleanField()

0 commit comments

Comments
 (0)