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:13:43 -0400 |
| commit | 175a102ddceae2ebd1a4e03916a23adafc35bda5 (patch) | |
| tree | be958ee858ff2a391637b34c2d5bb813953cff01 | |
| parent | a47116cb4c545b72f70ff61f192d59fd2e93fdad (diff) | |
Fixed #20567 - Documented BoundField.id_for_label.
Thanks littlepig for the suggestion.
| -rw-r--r-- | docs/ref/forms/api.txt | 23 | ||||
| -rw-r--r-- | docs/ref/forms/widgets.txt | 5 |
2 files changed, 27 insertions, 1 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 67e3aab712..c05430c64e 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -688,6 +688,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 diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 0f6917d44c..341574ad37 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -163,6 +163,9 @@ Django will then include the extra attributes in the rendered output: <tr><th>Url:</th><td><input type="url" name="url"/></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" size="40"/></td></tr> +You can also set the HTML ``id`` using :attr:`~Widget.attrs`. See +:attr:`BoundField.id_for_label` for an example. + .. _styling-widget-classes: Styling widget classes @@ -251,7 +254,7 @@ foundation for custom widgets. into two separate values:: from django.forms import MultiWidget - + class SplitDateTimeWidget(MultiWidget): # ... |
