/**
* @aValidity - boolean indicating whether the element is expected to be valid
* (aElement.validity.valid is true) or not. The value passed is ignored and
* overridden with true if aApply is false.
* @aApply - boolean indicating whether the min/max attributes apply to this
* element type.
* @aRangeApply - A boolean that's set to true if the current input type is a
* "[candidate] for constraint validation" and it "[has] range limitations"
* per http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html#selector-in-range
* (in other words, one of the pseudo classes :in-range and :out-of-range
* should apply (which, depends on aValidity)).
* Else (neither :in-range or :out-of-range should match) set to false.
*/
function checkValidity(aElement, aValidity, aApply, aRangeApply)
{
aValidity = aApply ? aValidity : true;
is(aElement.validity.valid, aValidity, "element validity should be " + aValidity);
is(aElement.validity.rangeUnderflow, !aValidity, "element underflow status should be " + !aValidity); var underflowMsg =
(aElement.type == "date" || aElement.type == "time" ||
aElement.type == "month" || aElement.type == "week" ||
aElement.type == "datetime-local") ?
("Please select a value that is no earlier than " + aElement.min + ".") :
("Please select a value that is no less than " + aElement.min + ".");
is(aElement.validationMessage,
aValidity ? "" : underflowMsg, "Checking range underflow validation message");
if (!aRangeApply) {
ok(!aElement.matches(":in-range"), ":in-range should not match");
ok(!aElement.matches(":out-of-range"), ":out-of-range should not match");
} else {
is(aElement.matches(":in-range"), aValidity, ":in-range matches status should be " + aValidity);
is(aElement.matches(":out-of-range"), !aValidity, ":out-of-range matches status should be " + !aValidity);
}
}
for (var test of data) { input.type = test.type; var apply = test.apply;
// The element should be valid. Range should not apply when @min and @max are
// undefined, except if the input type is 'range' (since that type has a
// default minimum and maximum).
if (input.type == 'range') {
checkValidity(input, true, apply, true);
} else {
checkValidity(input, true, apply, false);
}
switch (input.type) {
case 'hidden':
case 'text':
case 'search':
case 'password':
case 'url':
case 'tel':
case 'email':
case 'number':
case 'checkbox':
case 'radio':
case 'file':
case 'submit':
case 'reset':
case 'button':
case 'image':
case 'color': input.min = '999';
break;
case 'date': input.min = '2012-06-27';
break;
case 'time': input.min = '20:20';
break;
case 'range':
// range is special, since setting min to 999 will make it invalid since
// it's default maximum is 100, its value would be 999, and it would
// suffer from overflow.
break;
case 'month': input.min = '2016-06';
break;
case 'week': input.min = '2016-W39';
break;
case 'datetime-local': input.min = '2017-01-01T00:00';
break;
default:
ok(false, 'please, add a case for this new type (' + input.type + ')');
}
// The element should still be valid and range should apply if it can.
checkValidity(input, true, apply, apply);
switch (input.type) {
case 'text':
case 'hidden':
case 'search':
case 'password':
case 'tel':
case 'radio':
case 'checkbox':
case 'reset':
case 'button':
case 'submit':
case 'image':
case 'color': input.value = '0';
checkValidity(input, true, apply, apply);
break;
case 'url': input.value = 'http://mozilla.org';
checkValidity(input, true, apply, apply);
break;
case 'email': input.value = 'foo@bar.com';
checkValidity(input, true, apply, apply);
break;
case 'file': var file = new File([''], '635499_file');
// Check that we correctly convert input.min to a double in
// validationMessage. input.min = "4.333333333333333333333333333333333331"; input.value = "2";
is(input.validationMessage, "Please select a value that is no less than 4.33333333333333.", "validation message");
break;
case 'range': input.min = '0'; input.value = '1';
checkValidity(input, true, apply, apply);
// We don't check the conversion of input.min to a double in
// validationMessage for 'range' since range will always clamp the value
// up to at least the minimum (so we will never see the min in a
// validationMessage).
break;
case 'time':
// Don't worry about that. input.step = 'any';
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.