-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.html
executable file
·44 lines (37 loc) · 1.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
feature_name: reportValidity()
chrome_version: 40
feature_id: 5433505009893376
---
<h3>Background</h3>
<p>
This sample illustrates the use of
<code><a href="https://html.spec.whatwg.org/multipage/forms.html#dom-cva-reportvalidity">reportValidity()</a></code>,
which provides a way to trigger <code><form></code> validation logic.
If any of a <code><form></code>'s inputs are considered invalid, the offending inputs and the constraints
that are imposed will be identified in the user interface.
Additionally, <code>reportValidity()</code> returns a boolean value indicating whether all of the inputs
in the <code><form></code> were valid or not.
</p>
<p>
In this particular case, the <code><form></code> contains one <code><input></code>,
with two constraints: <code>required</code>, as well as
<code><a href="https://html.spec.whatwg.org/multipage/forms.html#attr-fe-minlength">minlength</a>="4"</code>.
</p>
{% capture initial_output_content %}
<form id="sample-form">
<div>
<label for="year">Enter at least four characters (required):</label>
<input id="year" type="text" minlength="4" required>
</div>
</form>
<button id="report-validity">Report Validity</button>
{% endcapture %}
{% include output_helper.html initial_output_content=initial_output_content %}
{% capture js %}
document.querySelector('#report-validity').addEventListener('click', function() {
var isValid = document.querySelector('#sample-form').reportValidity();
ChromeSamples.setStatus('The form ' + (isValid ? 'is' : 'is not') + ' valid.');
});
{% endcapture %}
{% include js_snippet.html js=js %}