BoundField.id_for_label
Use this property to render the ID of this field. For example, if you are manually constructing a <label>
in your template (despite the fact that label_tag()
will do this for you):
1 | < label for = "{{ form.my_field.id_for_label }}" >...</ label >{{ my_field }} |
By default, this will be the field’s name prefixed by id_
(“id_my_field
” for the example above). You may modify the ID by setting attrs
on the field’s widget. For example, declaring a field like this:
1 | my_field = forms.CharField(widget = forms.TextInput(attrs = { 'id' : 'myFIELD' })) |
and using the template above, would render something like:
1 | < label for = "myFIELD" >...</ label >< input id = "myFIELD" type = "text" name = "my_field" required /> |
Please login to continue.