Skip to content

Commit c1e5485

Browse files
nschonnijzaefferer
authored andcommitted
Split out skip_or_fill_minimum
1 parent 1ab8303 commit c1e5485

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

src/additional/additional.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,6 @@
3333

3434
}());
3535

36-
/*
37-
* Lets you say "either at least X inputs that match selector Y must be filled,
38-
* OR they must all be skipped (left blank)."
39-
*
40-
* The end result, is that none of these inputs:
41-
*
42-
* <input class="productinfo" name="partnumber">
43-
* <input class="productinfo" name="description">
44-
* <input class="productinfo" name="color">
45-
*
46-
* ...will validate unless either at least two of them are filled,
47-
* OR none of them are.
48-
*
49-
* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
50-
* description: {skip_or_fill_minimum: [2,".productinfo"]},
51-
* color: {skip_or_fill_minimum: [2,".productinfo"]}
52-
*
53-
*/
54-
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
55-
var validator = this,
56-
numberRequired = options[0],
57-
selector = options[1];
58-
var numberFilled = jQuery(selector, element.form).filter(function() {
59-
return validator.elementValue(this);
60-
}).length;
61-
var valid = numberFilled >= numberRequired || numberFilled === 0;
62-
63-
if(!jQuery(element).data('being_validated')) {
64-
var fields = $(selector, element.form);
65-
fields.data('being_validated', true);
66-
fields.valid();
67-
fields.data('being_validated', false);
68-
}
69-
return valid;
70-
}, jQuery.format("Please either skip these fields or fill at least {0} of them."));
71-
7236
// Accept a value from a file input based on a required mimetype
7337
jQuery.validator.addMethod("accept", function(value, element, param) {
7438
// Split mime on commas in case we have multiple types we can accept
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Lets you say "either at least X inputs that match selector Y must be filled,
3+
* OR they must all be skipped (left blank)."
4+
*
5+
* The end result, is that none of these inputs:
6+
*
7+
* <input class="productinfo" name="partnumber">
8+
* <input class="productinfo" name="description">
9+
* <input class="productinfo" name="color">
10+
*
11+
* ...will validate unless either at least two of them are filled,
12+
* OR none of them are.
13+
*
14+
* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
15+
* description: {skip_or_fill_minimum: [2,".productinfo"]},
16+
* color: {skip_or_fill_minimum: [2,".productinfo"]}
17+
*
18+
*/
19+
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
20+
var validator = this,
21+
numberRequired = options[0],
22+
selector = options[1];
23+
var numberFilled = jQuery(selector, element.form).filter(function() {
24+
return validator.elementValue(this);
25+
}).length;
26+
var valid = numberFilled >= numberRequired || numberFilled === 0;
27+
28+
if(!jQuery(element).data('being_validated')) {
29+
var fields = $(selector, element.form);
30+
fields.data('being_validated', true);
31+
fields.valid();
32+
fields.data('being_validated', false);
33+
}
34+
return valid;
35+
}, jQuery.format("Please either skip these fields or fill at least {0} of them."));

0 commit comments

Comments
 (0)