mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #27299 -- Documented the Widget.use_required_attribute() method.
Thanks Tim Graham for the review and edits.
This commit is contained in:
		| @@ -286,6 +286,29 @@ foundation for custom widgets. | |||||||
|         an HTML form submission, so it's unknown whether or not the user |         an HTML form submission, so it's unknown whether or not the user | ||||||
|         actually submitted a value. |         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`` | ``MultiWidget`` | ||||||
| --------------- | --------------- | ||||||
|  |  | ||||||
|   | |||||||
| @@ -858,7 +858,10 @@ Miscellaneous | |||||||
| * Required form fields now have the ``required`` HTML attribute. Set the | * Required form fields now have the ``required`` HTML attribute. Set the | ||||||
|   :attr:`Form.use_required_attribute <django.forms.Form.use_required_attribute>` |   :attr:`Form.use_required_attribute <django.forms.Form.use_required_attribute>` | ||||||
|   attribute to ``False`` to disable it. You could also add the ``novalidate`` |   attribute to ``False`` to disable it. You could also add the ``novalidate`` | ||||||
|   attribute to ``<form>`` if you don't want browser validation. |   attribute to ``<form>`` if you don't want browser validation. To disable | ||||||
|  |   the ``required`` attribute on custom widgets, override the | ||||||
|  |   :meth:`Widget.use_required_attribute() <django.forms.Widget.use_required_attribute>` | ||||||
|  |   method. | ||||||
|  |  | ||||||
| * The WSGI handler no longer removes content of responses from ``HEAD`` | * The WSGI handler no longer removes content of responses from ``HEAD`` | ||||||
|   requests or responses with a ``status_code`` of 100-199, 204, or 304. Most |   requests or responses with a ``status_code`` of 100-199, 204, or 304. Most | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user