#Button of type="button" is triggering post request

3 messages · Page 1 of 1 (latest)

vivid pasture
#

I am conditionally rendering the "Submit" type="submit" button when the currentForm is the last element in the formPartsArray, which is working fine. Issue is when I am clicking "Next" which is of type="button" to go the next part of the form but it is also triggering the post request. I am using react-hook-form. It should only trigger the onSubmit function when it is the last element of the form.

gusty karma
#

@vivid pasture You're defining an onSubmit method, but it doesn't look like it's used?

You're using methods.onSubmit instead.

charred lion
#

you can always try to cancel the bubbling of the event, or preventing the default behavior using stopPropagation and preventDefault respectively
tho a <button type="button"> shouldn't have a default behavior by default, so there is definitely something added by react-hook-form