Skip to content

Commit

Permalink
Clean up <input> typeMismatch constraint validation
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Jan 14, 2020
1 parent 4a374e5 commit 52109d5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/jsdom/living/nodes/HTMLInputElement-impl.js
Expand Up @@ -1014,22 +1014,26 @@ class HTMLInputElementImpl extends HTMLElementImpl {

// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#suffering-from-a-type-mismatch
typeMismatch: () => {
if (this._value === "") {
return false;
}
if (this.type === "email") {
switch (this.type) {
// https://html.spec.whatwg.org/multipage/input.html#url-state-(type=url)
// Constraint validation: While the value of the element is neither the empty string
// nor a valid absolute URL, the element is suffering from a type mismatch.
case "url":
if (this._value !== "" && !isValidAbsoluteURL(this._value)) {
return true;
}
break;

// https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)
// Constraint validation [multiple=false]: While the value of the element is neither the empty
// string nor a single valid e - mail address, the element is suffering from a type mismatch.

// Constraint validation [multiple=true]: While the value of the element is not a valid e-mail address list,
// the element is suffering from a type mismatch.
return !isValidEmailAddress(this._value, this.hasAttributeNS(null, "multiple"));
} else if (this.type === "url") {
// https://html.spec.whatwg.org/multipage/input.html#url-state-(type=url)
// Constraint validation: While the value of the element is neither the empty string
// nor a valid absolute URL, the element is suffering from a type mismatch.
return !isValidAbsoluteURL(this._value);
case "email":
if (this._value !== "" && !isValidEmailAddress(this._getValue(), this.hasAttributeNS(null, "multiple"))) {
return true;
}
break;
}
return false;
}
Expand Down

0 comments on commit 52109d5

Please sign in to comment.