This topic is locked
[SOLVED]

 JS Add/Remove validation(IsRequired)

9/15/2020 7:58:57 AM
PHPRunner General questions
D
david22585 author

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.

Sergey Kornilov admin 9/15/2020

Make sure you have the latest build of PHPRunner 10.4, we fixed a similar issue a while ago:

https://asprunner.com/forums/topic/27648-july-31-2020-phprunner-asprunnernet-asprunnerpro-104-maintenance-release/

D
david22585 author 9/15/2020



Make sure you have the latest build of PHPRunner 10.4, we fixed a similar issue a while ago:

https://asprunner.com/forums/topic/27648-july-31-2020-phprunner-asprunnernet-asprunnerpro-104-maintenance-release/


That was it! Didn't want to upgrade from 10.4x35427 until I was fully done with the project. Thanks!