Closed Bug 951887 Opened 10 years ago Closed 10 years ago

checkValidity on required input that's not in the DOM returns true because it's not considered mutable

Categories

(Core :: DOM: Core & HTML, defect)

26 Branch
x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla30

People

(Reporter: dunbarb2, Assigned: bzbarsky)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

Steps to reproduce:

Run the following javascript:

var input = document.createElement('input');
input.required = true;
console.log(input.checkValidity());


Actual results:

The output is 'true'.


Expected results:

The output should be 'false'.
Confirming in FF28; see this fiddle for reference: http://jsfiddle.net/MAeLA/
Component: Untriaged → DOM
Product: Firefox → Core
The spec at http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#the-required-attribute says:

  Constraint validation: If the element is required, and its value IDL attribute applies
  and is in the mode value, and the element is mutable, and the element's value is the
  empty string, then the element is suffering from being missing.

In this case, the element is required, the value IDL attribute applies and is in mode value, the elements value is the empty string.  

The spec doesn't have an actual centralized definition of "mutable".  At http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#the-input-element it says:

  Each input element can be mutable. Except where otherwise specified, an input element is
  always mutable. Similarly, except where otherwise specified, the user agent should not
  allow the user to modify the element's value or checkedness.

and then some more pieces:

  When an input element is disabled, it is not mutable.

  The readonly attribute is a boolean attribute that controls whether or not the user can
  edit the form control. When specified, the element is not mutable.

and maybe others; it's hard to tell, since they're scattered about.

In any case, our implementation treats all elements that are not in the DOM as not mutable.  That seems to date back to the original form validation checkin in bug 345822.

Mounir, do you recall why we do that?
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(mounir)
Summary: checkValidity on required input → checkValidity on required input that's not in the DOM returns true because it's not considered mutable
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
I am pretty sure this used to be a requirement. Something like a form control outside of a document is considered as non mutable. We could ask Hixie or check the HTML spec rev log. Though, I am not sure if that requirement (being in a document) is really useful.
Flags: needinfo?(mounir)
Whiteboard: [need review]
Attachment #8386415 - Flags: review?(bugs) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/c0d472d6e645
Flags: in-testsuite+
Whiteboard: [need review]
And https://hg.mozilla.org/integration/mozilla-inbound/rev/e7e2197a831d to fix the preexisting tests we had for this stuff.
https://hg.mozilla.org/mozilla-central/rev/c0d472d6e645
https://hg.mozilla.org/mozilla-central/rev/e7e2197a831d
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: