I have a form where there is a dropdown selector, and I need to make a 2nd field required if the drop down is a selected value. I have no issues with that, but where I have an issue is that if someone selects the wrong option that adds a validation, when they select the right option, it doesn't remove the validation. Here is my code:
var ctrl1 = Runner.getControl(pageid, 'usertype');
var ctrl2 = Runner.getControl(pageid, 'account_id');
ctrl1.on('change', function(e) {
if (this.getValue() == '2') {
ctrl2.addValidation("IsRequired");
} else if (this.getValue() == '3') {
ctrl2.addValidation("IsRequired");
} else if (this.getValue() == '4') {
ctrl2.addValidation("IsRequired");
} else if (this.getValue() == '5') {
ctrl2.removeValidation("IsRequired");
} else if (this.getValue() == '6') {
ctrl2.removeValidation("IsRequired");
}
});
For 2, 3, or 4 it works fine, IsRequired gets added. When I select option 5 or 6, it won't remove the validation IsRequired. If I select 5 or 6 right away, it doesn't add the validation.