mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #22383 -- Added support for HTML5 required attribute on required form fields.
This commit is contained in:
parent
4d1c229ee5
commit
ec6121693f
28 changed files with 849 additions and 659 deletions
|
@ -164,6 +164,11 @@ As we can see, ``formset.errors`` is a list whose entries correspond to the
|
|||
forms in the formset. Validation was performed for each of the two forms, and
|
||||
the expected error message appears for the second item.
|
||||
|
||||
Just like when using a normal ``Form``, each form in the formset may include
|
||||
HTML attributes such as ``maxlength`` for browser validation. However, forms of
|
||||
formsets won't include the ``required`` attribute as that validation may be
|
||||
incorrect when adding and deleting forms.
|
||||
|
||||
.. method:: BaseFormSet.total_error_count()
|
||||
|
||||
To check how many errors there are in the formset, we can use the
|
||||
|
|
|
@ -259,7 +259,7 @@ The whole form, when rendered for the first time, will look like:
|
|||
.. code-block:: html+django
|
||||
|
||||
<label for="your_name">Your name: </label>
|
||||
<input id="your_name" type="text" name="your_name" maxlength="100">
|
||||
<input id="your_name" type="text" name="your_name" maxlength="100" required />
|
||||
|
||||
Note that it **does not** include the ``<form>`` tags, or a submit button.
|
||||
We'll have to provide those ourselves in the template.
|
||||
|
@ -512,11 +512,11 @@ Here's the output of ``{{ form.as_p }}`` for our ``ContactForm`` instance:
|
|||
.. code-block:: html+django
|
||||
|
||||
<p><label for="id_subject">Subject:</label>
|
||||
<input id="id_subject" type="text" name="subject" maxlength="100" /></p>
|
||||
<input id="id_subject" type="text" name="subject" maxlength="100" required /></p>
|
||||
<p><label for="id_message">Message:</label>
|
||||
<textarea name="message" id="id_message"></textarea></p>
|
||||
<textarea name="message" id="id_message" required></textarea></p>
|
||||
<p><label for="id_sender">Sender:</label>
|
||||
<input type="email" name="sender" id="id_sender" /></p>
|
||||
<input type="email" name="sender" id="id_sender" required /></p>
|
||||
<p><label for="id_cc_myself">Cc myself:</label>
|
||||
<input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue