Skip to content

Commit 2f976f3

Browse files
sfreytagjzaefferer
authored andcommitted
Methods: Added require_from_group
Closes gh-5
1 parent dc921f6 commit 2f976f3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

entries/require_from_group-method.xml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<entry name="require_from_group" type="method" return="Boolean">
3+
<title>require_from_group method</title>
4+
<desc>Ensures a given number of fields in a group are complete.</desc>
5+
<longdesc>
6+
In the options passed to the rule, supply the minimum number of fields
7+
within the group that must be complete and a selector to define the
8+
group. Then apply this rule to all the fields within the group.
9+
The form then cannot be submitted until at least the minimum number have
10+
been completed.
11+
</longdesc>
12+
<example>
13+
<desc>Within a group of three phone numbers, ensure at least one is complete.</desc>
14+
<code><![CDATA[
15+
$( "#myform" ).validate({
16+
rules: {
17+
mobile_phone: {
18+
require_from_group: [1, ".phone-group"]
19+
},
20+
home_phone: {
21+
require_from_group: [1, ".phone-group"]
22+
},
23+
work_phone: {
24+
require_from_group: [1, ".phone-group"]
25+
}
26+
}
27+
});
28+
]]></code>
29+
<html><![CDATA[
30+
<label for="mobile_phone">Mobile phone: </label>
31+
<input class="left phone-group" id="mobile_phone" name="mobile_phone">
32+
<br/>
33+
<label for="home_phone">Home phone: </label>
34+
<input class="left phone-group" id="home_phone" name="home_phone">
35+
<br/>
36+
<label for="work_phone">Work phone: </label>
37+
<input class="left phone-group" id="Work_phone" name="work_phone">
38+
<br/>
39+
<input type="submit" value="Validate!">
40+
]]></html>
41+
</example>
42+
<category slug="methods"/>
43+
</entry>

pages/documentation.md

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Some more methods are provided as add-ons, and are currently included in additio
129129
* [`accept` - Makes a file upload accept only specified mime-types.](/accept-method)
130130
* [`extension` - Makes the element require a certain file extension.](/extension-method)
131131
* [`phoneUS` - Validate for valid US phone number.](/phoneUS-method)
132+
* [`require_from_group` - Ensures a given number of fields in a group are complete.](/require_from_group-method)
132133

133134
# [General Guidelines](/reference)
134135

0 commit comments

Comments
 (0)