3 ms·
From the WHATWG/W3C definitions of the maxlength attribute: > Constraint validation: If an element has a maximum allowed value length, its dirty value flag is
by jeroenhd 7y ago
From the WHATWG/W3C definitions of the maxlength attribute:
> Constraint validation: If an element has a maximum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), and the code-unit length of the element’s value is greater than the element’s maximum allowed value length, then the element is suffering from being too long.
> User agents may prevent the user from causing the element’s value to be set to a value whose code-unit length is greater than the element’s maximum allowed value length.
The key word, I think, is "may" in that user agents do not seem to be obligated to truncate text from what I can find in the standard.
While this does break the expectations from a developer point of view, I think it is perfectly in line with what users expect when they paste text. I think text falling off at the end after a paste with no explanation is more confusing than an the field glowing red with a message "you can only enter X characters here".
The old behaviour famously made people lose access to their PayPal account where the login form had a different maxlength as the registration form and where the password manager had put in a nice, long password. Preventing this sounds like a fine change for me, despite the compatibility break.
- fireattack 7y agoIn input.html [1] it says >If the input element has a maximum allowed value length, then the length of the value of the element's value attribute must be equal to or less than the element's maximum allowed value length. I'm a little bit confused, Which one should we follow? [1] https://html.spec.whatwg.org/multipage/input.html#attr-input-maxlength https://html.spec.whatwg.org/multipage/input.html#attr-input...
- Majromax 7y agoFrom 4.10.17.1 (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-value https://html.spec.whatwg.org/multipage/form-control-infrastr...): > A control's value is its internal state. As such, it might not match the user's current input. The example goes on to describe cases where a browser might remove padding spaces from a field, or refuse to register (as a value) a text entry in a numeric field.
- contravariant 7y agoArguably truncating the text is against the specification as it only specifies that the user agent may prevent the user from going beyond the max-length, not that it may do arbitrary stuff to make the text fit. I also hope it will make at least some developers realise that client-side validation is a bad idea.
- jeroenhd 7y agoI'd say the fact that it says that the user agent may, not must, truncate the text is a sign that this behaviour should not be expected. Failing the HTML5 validation is also perfectly reasonable. If people are building web pages right, this change will have little impact. Big if, of course, but a man can dream...