function checkNotSufferingFromBeingMissing(element, aTodo)
{
if (aTodo) {
ok = todo;
is = todo_is;
}
ok(!element.validity.valueMissing, "Element should not suffer from value missing");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "Element should be valid");
is(element.validationMessage, "", "Validation message should be the empty string");
ok(element.matches(":valid"), ":valid pseudo-class should apply");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(0, 128, 0)", ":valid pseudo-class should apply");
if (aTodo) {
ok = SimpleTest.ok;
is = SimpleTest.is;
}
}
function checkSufferingFromBeingMissing(element, aTodo)
{
if (aTodo) {
ok = todo;
is = todo_is;
}
ok(element.validity.valueMissing, "Element should suffer from value missing");
ok(!element.validity.valid, "Element should not be valid");
ok(!element.checkValidity(), "Element should not be valid");
is(element.validationMessage, "Please select an item in the list.", "Validation message is wrong");
is(window.getComputedStyle(element).getPropertyValue('background-color'), "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
if (aTodo) {
ok = SimpleTest.ok;
is = SimpleTest.is;
}
}
function checkRequiredAttribute(element)
{
ok('required' in element, "select should have a required attribute");
ok(!element.required, "select required attribute should be disabled");
is(element.getAttribute('required'), null, "select required attribute should be disabled");
element.required = true;
ok(element.required, "select required attribute should be enabled");
isnot(element.getAttribute('required'), null, "select required attribute should be enabled");
element.removeAttribute('required');
element.setAttribute('required', '');
ok(element.required, "select required attribute should be enabled");
isnot(element.getAttribute('required'), null, "select required attribute should be enabled");
element.removeAttribute('required');
ok(!element.required, "select required attribute should be disabled");
is(element.getAttribute('required'), null, "select required attribute should be disabled");
}
function checkRequiredAndOptionalSelectors(element)
{
is(document.querySelector("select:optional"), element, "select should be optional");
is(document.querySelector("select:required"), null, "select shouldn't be required");
element.required = true;
is(document.querySelector("select:optional"), null, "select shouldn't be optional");
is(document.querySelector("select:required"), element, "select should be required");
element.required = false;
}
function checkInvalidWhenValueMissing(element)
{
checkNotSufferingFromBeingMissing(select);
/**
* Non-multiple and size=1.
*/ select.appendChild(new Option());
checkSufferingFromBeingMissing(select);
// When removing the required attribute, element should not be invalid.
element.required = false;
checkNotSufferingFromBeingMissing(select);
element.required = true; select.options[0].textContent = "foo";
// TODO: having that working would require us to add a mutation observer on
// the select element.
checkNotSufferingFromBeingMissing(select, true);
// The placeholder label can only be the first option, so a selected empty second option is valid select.options[1].selected = true;
checkNotSufferingFromBeingMissing(select);
select.options[0].disabled = true;
// TODO: having that working would require us to add a mutation observer on
// the select element.
checkSufferingFromBeingMissing(select, true);
/**
* Non-multiple and size > 1.
* Everything should be the same except moving the selection.
*/ select.multiple = false; select.size = 4;
checkSufferingFromBeingMissing(select);
// Setting defaultSelected to true should not make the option selected select.add(new Option("", "", true), null);
checkSufferingFromBeingMissing(select); select.remove(0);
/**
* Multiple, any size.
* We can select more than one element and at least needs a value.
*/ select.multiple = true; select.size = 4;
checkSufferingFromBeingMissing(select);
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.