Monday, 29 December 2014

Disable/Enable validation controls using javascript

Now we are going to discuss about enable/disable validation controls using javascript.

Scenario : In my case, After validation is done then i am resetting the form but validation messages are not cleared. For this scenario i used the below method/technique for enable/disable the validations.

Enable Validator :

               for (i = 0; i < Page_Validators.length; i++) {
                       if (Page_Validators[i].validationGroup == "Box") {
                              ValidatorEnable(Page_Validators[i], true);

Disable Validator :

              for (i = 0; i < Page_Validators.length; i++) {
                      if (Page_Validators[i].validationGroup == "Cash") {
                        ValidatorEnable(Page_Validators[i], false);

Explanation :

Page_Validators.length -  Get the length of validation controls count.

Page_Validators[value].validationGroup - It is used to compare with the validation group name.

ValidatorEnable() - It is used to set either Enable/Disable the validation for that control.

ValidatorEnable(Page_Validators[i], false); - If true then enable validator or other wise disable the validation.

That's it.

Happy Coding :)