Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Stanislav Filin, 7 years ago

Owner: changed from nobody to Stanislav Filin
Status: newassigned

I can fix this

comment:2 by Mariusz Felisiak, 7 years ago

Triage Stage: UnreviewedAccepted
Version: 2.0master

comment:3 by Mariusz Felisiak, 7 years ago

Cc: Mariusz Felisiak added

comment:4 by Hasan Ramezani, 6 years ago

Has patch: set
Owner: changed from Stanislav Filin to Hasan Ramezani

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In f038214d:

Fixed #29056 -- Fixed HTML5 validation of required SelectDateWidget.

placeholder is required for "select" with "required" attribute.

comment:6 by Baptiste Mispelon, 5 years ago

Resolution: fixed
Severity: NormalRelease blocker
Status: closednew
Version: master3.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 Carlton Gibson, 5 years ago

Resolution: fixed
Severity: Release blockerNormal
Status: newclosed
Version: 3.0master

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 Carlton Gibson, 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:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In ee4a1905:

Fixed #31012 -- Reverted "Fixed #29056 -- Fixed HTML5 validation of required SelectDateWidget."

This reverts commit f038214d917c982613f5a15db8dfe325b1f7479b.

The initial issue was incorrect. Django 2.2, and before, did not
generate invalid HTML as reported. With f03821 in place invalid HTML
was generated.

Thanks to Kevin Brown for follow-up report and investigation.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 947f8e3:

[3.0.x] Fixed #31012 -- Reverted "Fixed #29056 -- Fixed HTML5 validation of required SelectDateWidget."

This reverts commit f038214d917c982613f5a15db8dfe325b1f7479b.

The initial issue was incorrect. Django 2.2, and before, did not
generate invalid HTML as reported. With f03821 in place invalid HTML
was generated.

Thanks to Kevin Brown for follow-up report and investigation.
Backport of ee4a19053a32d41cdd79e087b1968980804ce658 from master

comment:11 by Vlastimil Zíma, 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.

Note: See TracTickets for help on using tickets.
Back to Top