diff options
| author | Tim Graham <timograham@gmail.com> | 2013-06-06 14:15:26 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-06-09 12:16:56 -0400 |
| commit | 3bd9852401cfbc8a1dfec4082303a5514ee69bf4 (patch) | |
| tree | 46c1d89ad20cfe113562c2f10ed68255610678cb /docs/ref/forms/api.txt | |
| parent | 44a0abd7928b7f81a9b0e272b1dddd92f1913e0d (diff) | |
[1.5.x] Fixed #20567 - Documented BoundField.id_for_label.
Thanks littlepig for the suggestion.
Backport of 175a102ddc from master.
Diffstat (limited to 'docs/ref/forms/api.txt')
| -rw-r--r-- | docs/ref/forms/api.txt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 8d9e43bd3b..e6b0d3e6ee 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -683,6 +683,29 @@ by a ``Widget``:: >>> print(bound_form['subject'].value()) hi +.. attribute:: 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 +:meth:`~BoundField.label_tag` will do this for you): + +.. code-block:: html+django + + <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 +:attr:`~django.forms.Widget.attrs` on the field's widget. For example, +declaring a field like this:: + + my_field = forms.CharField(widget=forms.TextInput(attrs={'id': 'myFIELD'})) + +and using the template above, would render something like: + +.. code-block:: html + + <label for="myFIELD">...</label><input id="myFIELD" type="text" name="my_field" /> + .. _binding-uploaded-files: Binding uploaded files to a form |
