Submit a form depending on a condition

Hi, so I want to validate the submit only if my fetch to an api I am using is also submitted.

I tried to use it like this :

$w ( “#wixForms1” ). onWixFormSubmit (() => {
console . log ( res . error ?. data ?. details != undefined )
if ( res . error ?. data ?. details != undefined ){
return false
} else {
return true
}
})

So , “res . error ?. data ?. details” is defined only when there is an error.

But I don’t know why the code don’t run at all

Hello. If you look at the documentation for onWixFormSubmit , you can only validate with synchronous operations. Wix Fetch returns a promise so my guess is this is why your code is not working.

Is there another point in your flow where you can check this API? Perhaps not allowing the submit button to be active until the API is verified?