Constraint Validation API: tooLong property incorrect with prefilled value




6 years ago
3 years ago


(Reporter: tj.vantoll, Unassigned)


16 Branch

Firefox Tracking Flags

(Not tracked)




6 years ago
Per the spec ( a form control's validity.tooLong property should be "true if the element's value is longer than the provided maximum length; false otherwise."

However, if you have an input that has a preset value that is greater than its maxlength the tooLong property will still be false:

<input id="foo" type="text" maxlength="1" value="AB">
    document.getElementById('foo').validity.tooLong; //false

Furthermore when this element is in a form that form is allowed to submit -

Comment 1

3 years ago
This behavior is correct with respect to the now-current version of the spec.
Quoting from :
> If an element
> (1) has a maximum allowed value length,
> (2) **its dirty value flag is true,**
> (3) **its value was last changed by a user edit** (as opposed to a change made by a script),
> and (4) 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.
(Numbering and emphasis mine)

In your testcase, the value has never been modified, so the dirty value flag (2) is false, and the user has never edited the value, so (3) isn't satisfied either. Therefore, validity.tooLong should be false, which matches Firefox's current behavior.

Comment 2

3 years ago
Thanks for the reply. It's been long enough that I can't remember whether the spec has changed with regards to this behavior or not. I remember at the time I was investigating why Presto's implementation was different than Gecko's and WebKit's.

Your interpretation of the spec seems correct to me, so I'll close this out. Thanks.
Last Resolved: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.