1

We are using Django 1.4.3 to create our website. I had 2 forms with the same location selections (country, region and city) so I changed the html id by using

country_id = forms.ChoiceField(choices=COUNTRY_CHOICES, required=False, label=u'Country', widget=forms.Select(attrs={'id': 'id_select_country_id'}))

The form has labels but when I validated the HTML with http://validator.w3.org/check I got the following errors:

The for attribute of the label element must refer to a form control.
<label class="control-label" for="id_settings-country_id">Country</label>
<select id="id_select_country_id" name="settings-country_id">
....

How do I change the label's for attribute to match the id of the html select?

The form HTML elements are created automatically using

{{ settings_form|as_bootstrap:"horizontal" }}

We are using django-bootstrap-toolkit version 2.15.0 to render the form.

4

0 回答 0