form-validation-validity-stepMismatch.html (4765B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>The constraint validation API Test: element.validity.stepMismatch</title> 4 <link rel="author" title="Intel" href="http://www.intel.com/"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-validitystate-stepmismatch"> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-constraint-validation-api"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="support/validator.js"></script> 10 <div id="log"></div> 11 <script> 12 //set step = 2 * default step * factor 13 var testElements = [ 14 { 15 tag: "input", 16 types: ["date"], 17 testData: [ 18 {conditions: {step: "", value: "2000-01-01"}, expected: false, name: "[target] The step attribute is not set"}, 19 {conditions: {step: 2, value: ""}, expected: false, name: "[target] The value attibute is empty string"}, 20 {conditions: {step: 2, value: "1970-01-03"}, expected: false, name: "[target] The value must match the step"}, 21 {conditions: {step: 2, value: "1970-01-02"}, expected: true, name: "[target] The value must mismatch the step"} 22 ] 23 }, 24 { 25 tag: "input", 26 types: ["month"], 27 testData: [ 28 {conditions: {step: "", value: "2000-01"}, expected: false, name: "[target] The step attribute is not set"}, 29 {conditions: {step: 2, value: ""}, expected: false, name: "[target] The value attibute is empty string"}, 30 {conditions: {step: 2, value: "1970-03"}, expected: false, name: "[target] The value must match the step"}, 31 {conditions: {step: 2, value: "1970-04"}, expected: true, name: "[target] The value must mismatch the step"} 32 ] 33 }, 34 { 35 tag: "input", 36 types: ["week"], 37 testData: [ 38 {conditions: {step: "", value: "1970-W01"}, expected: false, name: "[target] The step attribute is not set"}, 39 {conditions: {step: 2, value: ""}, expected: false, name: "[target] The value attibute is empty string"}, 40 {conditions: {step: 2, value: "1970-W03"}, expected: false, name: "[target] The value must match the step"}, 41 {conditions: {step: 2, value: "1970-W04"}, expected: true, name: "[target] The value must mismatch the step"} 42 ] 43 }, 44 { 45 tag: "input", 46 types: ["time"], 47 testData: [ 48 {conditions: {step: "", value: "12:00:00"}, expected: false, name: "[target] The step attribute is not set"}, 49 {conditions: {step: 2 * 60, value: ""}, expected: false, name: "[target] The value attibute is empty string"}, 50 {conditions: {step: 2 * 60, value: "12:02:00"}, expected: false, name: "[target] The value must match the step"}, 51 {conditions: {step: 2 * 60, value: "12:03:00"}, expected: true, name: "[target] The value must mismatch the step"} 52 ] 53 }, 54 { 55 tag: "input", 56 types: ["datetime-local"], 57 testData: [ 58 {conditions: {step: "", value: "2000-01-01T12:00:00"}, expected: false, name: "[target] The step attribute is not set"}, 59 {conditions: {step: 2 * 60, value: ""}, expected: false, name: "[target] The value attibute is empty string"}, 60 {conditions: {step: 2 * 60, value: "1970-01-01T12:02:00"}, expected: false, name: "[target] The value must match the step"}, 61 {conditions: {step: 2 * 60, value: "1970-01-01T12:03:00"}, expected: true, name: "[target] The value must mismatch the step"} 62 ] 63 }, 64 { 65 tag: "input", 66 types: ["number"], 67 testData: [ 68 {conditions: {step: "", value: "1"}, expected: false, name: "[target] The step attribute is not set"}, 69 {conditions: {step: "", value: "-.8"}, expected: true, name: "[target] The step attribute is not set and the value attribute is a floating number"}, 70 {conditions: {step: 2 * 1 * 1, value: ""}, expected: false, name: "[target] The value attribute is empty string"}, 71 {conditions: {step: 2 * 1 * 1, value: "2"}, expected: false, name: "[target] The value must match the step"}, 72 {conditions: {step: 2 * 1 * 1, value: "3"}, expected: true, name: "[target] The value must mismatch the step"}, 73 {conditions: {step: 0.003, value: "3.6"}, expected: false, name: "[target] No step mismatch when step is a floating number and value is its integral multiple"}, 74 {conditions: {step: 1e-12, value: "-12345678.9"}, expected: false, name: "[target] No step mismatch when step is a floating number in exponent format and value is its integral multiple"}, 75 {conditions: {step: 3e-15, value: "17"}, expected: true, name: "[target] Step mismatch when step is a very small floating number and value is not its integral multiple"}, 76 ] 77 } 78 ]; 79 80 validator.run_test(testElements, "stepMismatch"); 81 </script>