Skip to content

Commit 0f343f0

Browse files
committed
victorjonsson#260 - Optional validation - Added ability to check if radio button with some value is checked (selected).
1 parent 7ab1aed commit 0f343f0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

form-validator/jquery.form-validator.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,10 @@
935935
validateIfCheckedElement = false,
936936

937937
// get value of this element's attribute "... if-checked"
938-
validateIfCheckedElementName = $elem.valAttr('if-checked');
938+
validateIfCheckedElementName = $elem.valAttr('if-checked'),
939+
// get expected radio button value for "if-checked" optional validation
940+
validateIfCheckedElementValue = $elem.valAttr('if-checked-value');
941+
939942

940943
if ($elem.attr('disabled') || (!$elem.is(':visible') && !conf.validateHiddenInputs)) {
941944
result.shouldChangeDisplay = false;
@@ -957,6 +960,23 @@
957960
// set value for validation checkpoint
958961
validationDependentInputIsChecked = true;
959962
}
963+
964+
// test if check input value
965+
if (validateIfCheckedElementValue != null) {
966+
validateIfCheckedElement.each(function(index, el) {
967+
// test if it's property "checked" is checked and value equals expected value
968+
if ($(el).prop('checked') && $(el).val() === validateIfCheckedElementValue) {
969+
validationDependentInputIsChecked = true;
970+
}
971+
});
972+
}
973+
else {
974+
// test if it's property "checked" is checked
975+
if (validateIfCheckedElement.prop('checked')) {
976+
// set value for validation checkpoint
977+
validationDependentInputIsChecked = true;
978+
}
979+
}
960980
}
961981

962982
// validation checkpoint

0 commit comments

Comments
 (0)