Skip to content

Commit 4df4064

Browse files
committed
Merge pull request victorjonsson#313 from Igloczek/issue/260
Optional validation - Radio buttons support
2 parents c0453cb + 98b9dee commit 4df4064

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

form-validator/jquery.form-validator.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,10 @@
944944
validateIfCheckedElement = false,
945945

946946
// get value of this element's attribute "... if-checked"
947-
validateIfCheckedElementName = $elem.valAttr('if-checked');
947+
validateIfCheckedElementName = $elem.valAttr('if-checked'),
948+
// get expected radio button value for "if-checked" optional validation
949+
validateIfCheckedElementValue = $elem.valAttr('if-checked-value');
950+
948951

949952
if ($elem.attr('disabled') || (!$elem.is(':visible') && !conf.validateHiddenInputs)) {
950953
result.shouldChangeDisplay = false;
@@ -961,10 +964,21 @@
961964
// select the checkbox type element in this form
962965
validateIfCheckedElement = $form.find('input[name="' + validateIfCheckedElementName + '"]');
963966

964-
// test if it's property "checked" is checked
965-
if (validateIfCheckedElement.prop('checked')) {
966-
// set value for validation checkpoint
967-
validationDependentInputIsChecked = true;
967+
// test if check input value
968+
if (validateIfCheckedElementValue != null) {
969+
validateIfCheckedElement.each(function(index, el) {
970+
// test if it's property "checked" is checked and value equals expected value
971+
if ($(el).prop('checked') && $(el).val() === validateIfCheckedElementValue) {
972+
validationDependentInputIsChecked = true;
973+
}
974+
});
975+
}
976+
else {
977+
// test if it's property "checked" is checked
978+
if (validateIfCheckedElement.prop('checked')) {
979+
// set value for validation checkpoint
980+
validationDependentInputIsChecked = true;
981+
}
968982
}
969983
}
970984

0 commit comments

Comments
 (0)