/**
* @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.rangeOverflow, !aValidity, "element overflow status should be " + !aValidity); var overflowMsg =
(aElement.type == "date" || aElement.type == "time" ||
aElement.type == "month" || aElement.type == "week" ||
aElement.type == "datetime-local") ?
("Please select a value that is no later than " + aElement.max + ".") :
("Please select a value that is no more than " + aElement.max + ".");
is(aElement.validationMessage,
aValidity ? "" : overflowMsg, "Checking range overflow 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);
}
checkValidity(input, true, apply, test.type == 'range');
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.max = '-1';
break;
case 'date': input.max = '2012-06-27';
break;
case 'time': input.max = '02:20';
break;
case 'range':
// range is special, since setting max to -1 will make it invalid since
// it's default would then be 0, meaning it suffers from overflow. input.max = '-1';
checkValidity(input, false, apply, apply);
// Now make it something that won't cause an error below: input.max = '10';
break;
case 'month': input.max = '2016-12';
break;
case 'week': input.max = '2016-W39';
break;
case 'datetime-local': input.max = '2016-12-31T23:59:59';
break;
default:
ok(false, 'please, add a case for this new type (' + input.type + ')');
}
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': 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.max to a double in validationMessage.
if (input.type == 'number') { input.max = "4.333333333333333333333333333333333331"; input.value = "5";
is(input.validationMessage, "Please select a value that is no more than 4.33333333333333.", "validation message");
}
// Check that we correctly convert input.max to a double in validationMessage. input.step = 'any'; input.min = 5; input.max = 0.6666666666666666; input.value = 1;
is(input.validationMessage, "Please select a value that is no more than 0.666666666666667.", "validation message")
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.