How to trigger a function when trying to submit a form using vazco/uniforms?

I am trying to call a function when the user clicks on the submit button inside an AutoForm from the vazco/uniforms components. I’m also using the parameter schema={schema} to validate if the form data is correct. What happens is if the form is incorrect, I didn’t find a way to trigger the function. How can I set it on the AutoForm?

Detail: I need to be just when the user clicks on the button submit of the form.

I have:


I know I can write:

onValidate={(modelTmp, error, callback) => {..}}

and also

modelTransform={(mode, model) => {..}}

but with this functions I don’t know if the user just clicked on the submit button, or if he is typing something on the form and it is changing the model.

Any idea how to solve it?


If you are passing children to the AutoForm component rather than letting it just render the whole form, then you could always just put a regular submit button inside and attach a function to the onClick prop. As long as you don’t call event.preventDefault inside that function you should get your desired result.

You can simply render a button (normal HTML tag) with your event listener and call event.preventDefault() when submit should be intercepted. By the way, why do you want to do so?