diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-10-22 08:15:33 -0700 |
|---|---|---|
| committer | Jon Dufresne <jon.dufresne@gmail.com> | 2016-10-26 19:29:16 -0700 |
| commit | c74378bb77db5bbeac1bd48c0cd31154f96a81d6 (patch) | |
| tree | 5254eb5de002c90d3c146b3024593c6295902f07 /docs/ref | |
| parent | f734e2d4b2fc4391a4d097b80357724815c1d414 (diff) | |
Fixed #27299 -- Documented the Widget.use_required_attribute() method.
Thanks Tim Graham for the review and edits.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/forms/widgets.txt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 99514e46a2..c6148a5460 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -286,6 +286,29 @@ foundation for custom widgets. an HTML form submission, so it's unknown whether or not the user actually submitted a value. + .. method:: use_required_attribute(initial) + + .. versionadded:: 1.10.1 + + Given a form field's ``initial`` value, returns whether or not the + widget can be rendered with the ``required`` HTML attribute. Forms use + this method along with :attr:`Field.required + <django.forms.Field.required>` and :attr:`Form.use_required_attribute + <django.forms.Form.use_required_attribute>` to determine whether or not + to display the ``required`` attribute for each field. + + By default, returns ``False`` for hidden widgets and ``True`` + otherwise. Special cases are :class:`~django.forms.ClearableFileInput`, + which returns ``False`` when ``initial`` is not set, and + :class:`~django.forms.CheckboxSelectMultiple`, which always returns + ``False`` because browser validation would require all checkboxes to be + checked instead of at least one. + + Override this method in custom widgets that aren't compatible with + browser validation. For example, a WSYSIWG text editor widget backed by + a hidden ``textarea`` element may want to always return ``False`` to + avoid browser validation on the hidden field. + ``MultiWidget`` --------------- |
