Skip to content

Commit cc97fa0

Browse files
committed
victorjonsson#594 Support several inputs depending on the value of one other input
1 parent 4bb4a2d commit cc97fa0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/modules/logic.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@
5353
},
5454
dependingOnValueChanged = function() {
5555
var $input = $(this),
56-
$otherInput = this.$dependingInput,
57-
valueOfDependingInput = $.formUtils.getValue($input),
58-
requiredValueOfDependingInput = $input.valAttr('depending-value'),
59-
otherInputHasValue = $.formUtils.getValue($otherInput) ? true:false,
60-
dependingInputIsMissingValueOrHasIncorrectValue = !valueOfDependingInput || (
61-
requiredValueOfDependingInput &&
62-
requiredValueOfDependingInput !== valueOfDependingInput
63-
);
64-
65-
if (dependingInputIsMissingValueOrHasIncorrectValue && !otherInputHasValue) {
66-
$.formUtils.dialogs.removeInputStylingAndMessage($otherInput, conf);
67-
}
56+
inputValue = $.formUtils.getValue($input),
57+
requiredValueOfDependingInput = $input.valAttr('depending-value');
58+
$.each(this.dependingInputs, function (i, $otherInput) {
59+
var otherInputHasValue = $.formUtils.getValue($otherInput) ? true:false,
60+
dependingInputIsMissingValueOrHasIncorrectValue = !inputValue || (
61+
requiredValueOfDependingInput &&
62+
requiredValueOfDependingInput !== inputValue
63+
);
64+
65+
if (dependingInputIsMissingValueOrHasIncorrectValue && !otherInputHasValue) {
66+
$.formUtils.dialogs.removeInputStylingAndMessage($otherInput, conf);
67+
}
68+
});
6869
};
6970

7071
$form.find('[data-validation-depends-on]')
@@ -79,10 +80,9 @@
7980
.on('change', dependingOnValueChanged)
8081
.valAttr('depending-value', $dependingInput.valAttr('depends-on-value'));
8182

82-
this.$dependingInput = $dependingInput;
83-
83+
this.dependingInputs = this.dependingInputs || [];
84+
this.dependingInputs.push($dependingInput);
8485
});
85-
8686
});
8787

8888
},

0 commit comments

Comments
 (0)