Proposal: Use HTML5 boolean attribute for checked on checkbox/radio inputs

150 views
Skip to first unread message

Jon Dufresne

unread,
Jul 22, 2016, 5:30:58 PM7/22/16
to django-d...@googlegroups.com
Hi,

I would like to propose that Django renders the "checked" attribute of checkbox and radio inputs using the HTML5 boolean style attributes.

Django has supported HTML5 boolean attributes since 1.8 [0]. It has used them internally for the "disabled" attribute since 1.9 [1] and the "required" attribute starting with 1.10 [2]. So there is some precedent to using the HTML5 style. I find the newer style cleaner and more in line with modern conventions.

I have created a ticket [3] with this proposal as well as a PR [4].

One concern raised in the ticket is backwards compatibility with non-HTML5 doctypes. I'm not aware of any such issues with modern browsers. I have tested older doctypes on Firefox and Chrome, both accept the HTML5 boolean style with HTML4 and XHTML doctypes. Currently, I do not have access to IE, so I am unable to test those cases. If anyone is interested to test, there is a very simple test case in the ticket.

Additionally, if there is an issue with older doctypes, presumably this issue already exists with the disabled and required attributes.

Just reaching out for feedback, concerns, and comments.

Thanks!

Cheers,
Jon


[0] https://docs.djangoproject.com/en/dev/releases/1.8/#forms
[1] https://github.com/django/django/blob/stable/1.9.x/django/forms/boundfield.py#L88-L89
[2] https://github.com/django/django/blob/stable/1.10.x/django/forms/boundfield.py#L88-L89
[3] Ticket: https://code.djangoproject.com/ticket/26928
[4] PR: https://github.com/django/django/pull/6961

Claude Paroz

unread,
Jul 23, 2016, 3:07:08 AM7/23/16
to Django developers (Contributions to Django itself)
Le vendredi 22 juillet 2016 23:30:58 UTC+2, Jon Dufresne a écrit :
Hi,

I would like to propose that Django renders the "checked" attribute of checkbox and radio inputs using the HTML5 boolean style attributes.
(...)

I'm definitely +1 with this change.
Hopefully, 1.11 should come with template-based widget rendering, so as people who need it can customize the default output.

Claude

Florian Apolloner

unread,
Jul 23, 2016, 4:21:22 AM7/23/16
to Django developers (Contributions to Django itself)
This should be perfectly fine -- I guess just nobody got around to do it yet. The main issue with the HTML5 stuff is around date&time where it is not clearly specified (or was last time I looked) what the UA should send and how to handle that in browsers not supporting HTML5 yet (ie sending iso date/time is not so nice when you want to display it localized). The required attribute was also problematic in the sense that now hidden (unused) forms with required would prevent the page from validating etc… So any change like yours currently, which does not introduce such issues should be no problem.

Cheers,
Florian

Tim Graham

unread,
Jul 25, 2016, 8:36:09 AM7/25/16
to Django developers (Contributions to Django itself)
I was wondering if it causes any HTML validation problems for other doctypes? If so, we might document that Django's default HTML rendering targets the HTML5 doctype.

Jon Dufresne

unread,
Jul 25, 2016, 8:57:21 PM7/25/16
to django-d...@googlegroups.com
> I was wondering if it causes any HTML validation problems for other doctypes?

True. A strict validator for XHTML will flag HTML5 syntax as an error. It isn't a part of the XHTML spec. From my testing it seems like modern browsers can handle this, but you're right, validators will catch it.

> If so, we might document that Django's default HTML rendering targets the HTML5 doctype.

Makes sense to me. I've updated PR with additional documentation that mentions this.

Cheers,
Jon
Reply all
Reply to author
Forward
0 new messages