Conditional statements can be used to disable cow authentication when both cat1 and cat2 are selected.
cat1: function(){
this.validObj.challenge('cat1', 'cat1') && this.validObj.required();
this.disableCowValidation();
},
cat2: function(){
this.validObj.challenge('cat2', 'cat2') && this.validObj.required();
this.disableCowValidation();
},
cow1: function(){
if (!this.isCowValidationDisabled()) {
this.validObj.challenge('cow1', 'cow1') && this.validObj.required();
}
},
cow2: function(){
if (!this.isCowValidationDisabled()) {
this.validObj.challenge('cow2', 'cow2') && this.validObj.required();
}
},
isCowValidationDisabled: function() {
return $('#cat1').val() && $('#cat2').val();
},
disableCowValidation: function() {
if (this.isCowValidationDisabled()) {
$('#cow1, #cow2').removeAttr('required');
} else {
$('#cow1, #cow2').attr('required', 'required');
}
},
In the validation function of each select, in addition to validating the input, the disableCowValidation method is called.
ThedisableCowValidation method determines whether to disable cow authentication. If yes, it removes the required attribute of cow. If not, add the required attribute.
TheisCowValidationDisabled method checks whether cat1 and cat2 have non-null options. If both options are selected, cow authentication needs to be disabled.