Skip to content

Commit c3ce5b4

Browse files
mlynchjzaefferer
authored andcommitted
Added checkbox test to require_from_group and changed require_from_group to use elementValue. Fixes jquery-validation#359
1 parent a24e58a commit c3ce5b4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

additional-methods.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ jQuery.validator.addMethod("pattern", function(value, element, param) {
336336
*
337337
*/
338338
jQuery.validator.addMethod("require_from_group", function(value, element, options) {
339+
var validator = this;
339340
var selector = options[1];
340341
var validOrNot = $(selector, element.form).filter(function() {
341-
return $(this).val();
342+
return validator.elementValue(this);
342343
}).length >= options[0];
343344

344345
if(!$(element).data('being_validated')) {
@@ -369,10 +370,12 @@ jQuery.validator.addMethod("require_from_group", function(value, element, option
369370
*
370371
*/
371372
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
373+
var validator = this;
374+
372375
numberRequired = options[0];
373376
selector = options[1];
374377
var numberFilled = $(selector, element.form).filter(function() {
375-
return $(this).val();
378+
return validator.elementValue(this);
376379
}).length;
377380
var valid = numberFilled >= numberRequired || numberFilled === 0;
378381

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ <h3></h3>
286286
<input class="productInfo" name="partnumber">
287287
<input class="productInfo" name="description">
288288
<input class="productInfo" name="color">
289+
<input class="productInfo" type="checkbox" name="discount" />
289290
</form>
290291

291292
</div>

test/methods.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,19 @@ test('require_from_group', function() {
700700
$("#productInfo").validate({
701701
rules: {
702702
partnumber: {require_from_group: [2,".productInfo"]},
703-
description: {require_from_group: [2,".productInfo"]}
703+
description: {require_from_group: [2,".productInfo"]},
704+
discount: {require_from_group: [2,".productInfo"]}
704705
}
705706
});
706707

707708
fillFormWithValuesAndExpect('#productInfo', [], false);
708709
fillFormWithValuesAndExpect('#productInfo', [123], false);
710+
$('#productInfo input[type="checkbox"]').attr('checked', 'checked');
711+
fillFormWithValuesAndExpect('#productInfo', [123], true);
712+
$('#productInfo input[type="checkbox"]').removeAttr('checked');
709713
fillFormWithValuesAndExpect('#productInfo', [123, 'widget'], true);
710714
fillFormWithValuesAndExpect('#productInfo', [123, 'widget', 'red'], true);
715+
fillFormWithValuesAndExpect('#productInfo', [123, 'widget', 'red'], true);
711716
});
712717

713718
test('skip_or_fill_minimum', function() {

0 commit comments

Comments
 (0)