#29056 closed Bug (fixed)
Required SelectDateWidget renders invalid HTML
Reported by: | Vlastimil Zíma | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Mariusz Felisiak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
SelectDateWidget
in required field renders an invalid HTML. According to standard https://www.w3.org/TR/html5/sec-forms.html#placeholder-label-option every select
with required
attribute must have a placeholder option, i.e. first option must have an empty string as a value. That is not a case of SelectDateWidget
.
Example
from django import forms class FooForm(forms.Form): a_date = forms.DateField(widget=forms.SelectDateWidget) form = FooForm() str(form) # >>> ...<select name="a_date_month" required id="id_a_date_month"><option value="1">January</option>...
Change History (11)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 2.0 → master |
comment:3 by , 7 years ago
Cc: | added |
---|
comment:4 by , 6 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
comment:6 by , 5 years ago
Resolution: | fixed |
---|---|
Severity: | Normal → Release blocker |
Status: | closed → new |
Version: | master → 3.0 |
According to #31012 (which I just closed as a duplicated), the fix for this ticket is not correct (and should probably be reverted).
There's more detail in the duplicate ticket but if I understand correctly, the term "placeholder" in the spec does not refer to the "placeholder" attribute that other tags can have.
A "placeholder" option is an <option>
tag with an empty value that has to be the first direct element of the <select>
.
The duplicate ticket has a pull request at https://github.com/django/django/pull/12116.
comment:7 by , 5 years ago
Resolution: | → fixed |
---|---|
Severity: | Release blocker → Normal |
Status: | new → closed |
Version: | 3.0 → master |
HI Baptiste. The new ticket is highlighting a regression introduced here. It's not a duplicate. But it will be a Release Blocker, yes. (I'm just Reviewing it now...)
comment:8 by , 5 years ago
Worth noting for future reference from #31012:
It's also important to note that the HTML generated for the SelectDateWidget in previous versions of Django was valid per the HTML standard. They did not contain a placeholder label option, but because they were not a <select multiple> they always contained an option with a selectedness set to true (usually the first option). This meant that the required attribute generated for them was useless, since it would never not have a value or be empty, but it did mean it was still valid HTML.
comment:11 by , 5 years ago
When reported, the SelectDateWidget
actually rendered invalid HTML, but it was fixed as a side-effect of #29036. Looks like I've created this ticket during the discussion and forgot to close it afterwards.
I can fix this