/**
* This test is checking only tooLong related features
* related to constraint validation.
*/
function checkTooLongValidity(element)
{
element.value = "foo";
ok(!element.validity.tooLong, "Element should not be too long when maxlength is not set");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "The element should be valid");
element.maxLength = 1;
ok(!element.validity.tooLong, "Element should not be too long unless the user edits it");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "The element should be valid");
element.focus();
synthesizeKey("KEY_Backspace");
is(element.value, "fo", "value should have changed");
ok(element.validity.tooLong, "Element should be too long after a user edit that does not make it short enough");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
ok(!element.validity.valid, "Element should be invalid");
ok(!element.checkValidity(), "The element should not be valid");
is(element.validationMessage, "Please shorten this text to 1 characters or less (you are currently using 2 characters).", "The validation message text is not correct");
synthesizeKey("KEY_Backspace");
is(element.value, "f", "value should have changed");
ok(!element.validity.tooLong, "Element should not be too long after a user edit makes it short enough");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
element.maxLength = 2;
ok(!element.validity.tooLong, "Element should remain valid if maxlength changes but maxlength > length");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
element.maxLength = 1;
ok(!element.validity.tooLong, "Element should remain valid if maxlength changes but maxlength = length");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "The element should be valid");
element.maxLength = 0;
ok(element.validity.tooLong, "Element should become invalid if maxlength changes and maxlength < length");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
ok(!element.validity.valid, "Element should be invalid");
ok(!element.checkValidity(), "The element should not be valid");
is(element.validationMessage, "Please shorten this text to 0 characters or less (you are currently using 1 characters).", "The validation message text is not correct");
element.maxLength = 1;
ok(!element.validity.tooLong, "Element should become valid if maxlength changes and maxlength = length");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "The element should be valid");
element.value = "test";
ok(!element.validity.tooLong, "Element should stay valid after programmatic edit (even if value is too long)");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "The element should be valid");
element.setCustomValidity("custom message");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
is(element.validationMessage, "custom message", "Custom message should be shown instead of too long one");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.