Join the Team Forms community

E
R
A
T
C

Prevent custom button action execution on validation failure

Last updated last week
M
Muffins


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?

E
Erin Dwyer
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
E
Erin Dwyer

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
}


M
Muffins

it works very well.