Join the Team Forms community

Updated 5 months ago

Prevent custom button action execution on validation failure

At a glance
The community member created a button with dual actions, but if the validation fails, the other actions are still executed except for the Submit action. They don't want to use the 'Disable on invalid forms' option because it doesn't show the invalid components. Another community member suggests using the undocumented instance.root.checkValidity() function, which returns true if all fields are valid and false if there are any invalid fields. This can be used to conditionally run different parts of the code, for example, only executing the instance.emit("submitButton") if the form is valid.


I created the following dual actions on the button, with the 'show validations' option turned on.

However, if the validation fails, the other actions are still executed on click except for Submit.

I don't want to use the 'Disable on invalid forms' option because it doesn't show me the invalid components.

How do I make sure that all actions are only executed if the validation succeeds?

Marked as solution

Hi Muffins

There is an undocumented function you can call called instance.root.checkValidity()which will return true if all fields are valid and false if there are any invalid fields in the response. Using this function, you could conditionally run different parts of your code for example:

JavaScript
instance.emit("submitButton")
if(instance.root.checkValidity()){
	// Do something
}


View full solution
E
M
1 comment·1 reply

Hi Muffins

There is an undocumented function you can call called instance.root.checkValidity()which will return true if all fields are valid and false if there are any invalid fields in the response. Using this function, you could conditionally run different parts of your code for example:

JavaScript
instance.emit("submitButton")
if(instance.root.checkValidity()){
	// Do something
}


it works very well.