Skip to main content
Nintex Community Menu Bar

Trigger Validation Rules via Javascript

  • July 14, 2022
  • 4 replies
  • 492 views

Forum|alt.badge.img+3

Hi how to trigger validation rules via Javascript? I have tried using Page_ClientValidate() but it is not highlighting the fields not like when clicking the Save and Submit Button.

 

Thanks for your help.

4 replies

MegaJerk
Forum|alt.badge.img+14
  • Scholar
  • July 22, 2022

While the Page_ClientValidate() function does evaluate and run all of the rules, it doesn't handle any of the styling on the controls to indicate that they are in error. To get that working you'll need to use a function called ValidationSummaryOnSubmit that is invoked anytime an onSubmit event is triggered.

 

Example Code:

if (!Page_ClientValidate();) { ValidationSummaryOnSubmit(NWF$(".nf-validation-summary").prop("validationGroup")); }

 

Note: The ValidationSummaryOnSubmit function requires a validationGroup string that can be found as a property on the actual form element that is where all of the Error Text is located in red at the top of your form. This is why I am targeting that element using the ".nf-validation-summary" class, and getting that particular property to pass into the function 😉 

Any who, this should be easy enough to test. Let me know if it works. 

 


MegaJerk
Forum|alt.badge.img+14
  • Scholar
  • July 25, 2022

There was a small typo in the code above, but I can no longer edit my post. I had added an unneeded semi-colon after the (!Page_ClientValidate()). In the code example below is a corrected version:

if (!Page_ClientValidate()) { ValidationSummaryOnSubmit(NWF$(".nf-validation-summary").prop("validationGroup")); }

 


MegaJerk
Forum|alt.badge.img+14
  • Scholar
  • July 25, 2022

Also, if this solved your issue, please mark the post as the solution so it can go into the Solved category of posts. Thank you! 

 


Forum|alt.badge.img
  • Novice
  • February 22, 2023

working perfect, thanks.

I created a button with the code, to stay on the form, even when the validation did not find any issues.