Opened 22 months ago

Closed 22 months ago

Last modified 21 months ago

#20630 closed Bug (fixed)

HTML5 validation broken by maxlength attributes in number inputs

Reported by: yoyoma Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: html5
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The commit for #19686 adds maxlength to number inputs with max digits (https://code.djangoproject.com/attachment/ticket/19686/ticket-19686-claudep-github-revised.diff#L85)

Paste the following into http://validator.w3.org/#validate_by_input and submit:

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <div>
            <input type="number" maxlength="5">
        </div>
    </body>
</html>

One of the messages you'll notice is: maxlength when type is text, search, url, tel, e-mail, or password.

So, it appears that HTML5 doesn't allow a maxlength attribute for number inputs.

Attachments (1)

0001-Fixed-20630-Removed-maxlength-attribute-from-NumberI.patch (4.1 KB) - added by charettes 22 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 22 months ago by charettes

  • Component changed from Uncategorized to Forms
  • Keywords html5 added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug
  • Version changed from 1.6-alpha-1 to master

Agreed that we should remove this attribute on number input, I guess we overlooked this :/

I'll write a patch removing this feature and making sure tests don't fail. Should we add a release note concerning this change?

comment:2 Changed 22 months ago by charettes

  • Has patch set

Added a patch for review, the only possibly missing part is the release note.

comment:3 Changed 22 months ago by bmispelon

  • Triage Stage changed from Accepted to Ready for checkin

The patch looks good.

7ec2a21be15af5b2c7513482c3bcfdd1e12782ed was committed after the 1.5 release and already includes a release note.
The note makes no mention of maxlength specifically, so I think we're good.

comment:4 Changed 22 months ago by charettes

Great, I'll commit this. I thought we shipped this feature in 1.5, thanks for looking this up!

comment:5 Changed 22 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 04628e2016641bfa657333d6ee1f5b371c17f62c:

Fixed #20630 -- Removed maxlength attribute from NumberInput.

This attribute is only allowed on inputs of type "text", "search", "url",
"tel", "email", or "password".

Thanks to yoyoma for the report and @bmispelon for the review.

comment:6 Changed 21 months ago by yoyoma

Thanks bmispelon and charettes. I'm sorry I didn't make it back in time to offer codereview support. You guys are friggin quick.

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