required()Returns: Boolean
Description: Makes the element required.
-
required()
-
This signature does not accept any arguments.
-
-
required( dependency-expression )
-
dependency-expressionType: StringAn expression (String) that is evaluated in the context of the element's form, making the field required only if the expression returns more than one element.
Very often your expression will use selector filters such as
#foo:checked
,#foo:filled
,#foo:visible
. This plugin provides custom selectors for that purpose.
-
-
required( dependency-callback )
-
dependency-callbackType: Function()The function is executed with the element as it's only argument: If it returns true, the element is required.
-
Return false, if the element is empty (text input) or unchecked (radio/checkbox) or if nothing is selected (select).
Works with text inputs, selects, checkboxes and radio buttons.
To force a user to select an option from a select box, provide an empty option element like <option value="">Choose…</option>
Note that white spaces are considered valid.
Examples:
Example: Makes "field" always required.
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
|
|
Demo:
Example: Makes the fruit select required.
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
|
|
Demo:
Example: Makes the gender radio buttons required.
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
|
|
Demo:
Example: Makes the agree checkbox required.
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
|
|
Demo:
Example: Makes details required only if #other is checked.
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
|
|
Demo:
Example: Makes "parent" required only if age is below 13.
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
|
|