damianricobelli / stepperize

A library for creating step-by-step workflows in your apps
https://stepperize.vercel.app
844 stars 38 forks source link

Footer Buttons submit Form #1

Closed RocketDav1d closed 4 months ago

RocketDav1d commented 5 months ago

First off, great component, thanks for building! When using the Footer component inside a Form component clicking any Footer Button will result in the submit of the form

I found a workaround which effectively prevents the submission of the form <Button size="sm" onClick={(event) => { if (!isLastStep) event.preventDefault(); nextStep(); }}> {isLastStep ? "Finish" : isOptionalStep ? "Skip" : "Next"} </Button>

damianricobelli commented 5 months ago

Hey @RocketDav1d thank you very much and also for your comment. I will review this detail in the next few days

damianricobelli commented 5 months ago

@RocketDav1d could you give me a complete example of your use case?

ruru-m07 commented 5 months ago

need more info to resolve

CosAnca commented 4 months ago

A <button> without an explicit type placed inside a <form> has by default type="submit" which will...submit the form. More details here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#type Shadcn UI <Button> component doesn't have a type assign to it by default, so you need to add type="button" to the <Button> component if you don't want it to submit the form.

damianricobelli commented 4 months ago

@CosAnca would you like to create a PR with the fix?

abeisleem commented 4 months ago

@RocketDav1d, ez set button type=button

ex:

<Button
  size="sm"
  type="button"
  onClick={(event) => {
    // if (!isLastStep) event.preventDefault(); // remove this preventDefault()
    nextStep();
  }}
>
  {isLastStep ? 'Finish' : isOptionalStep ? 'Skip' : 'Next'}
</Button>

I don't think this is PR worthy. It's a common behavior that the developer should be aware of.

abeisleem commented 4 months ago

Created a PR anyway to reflect this requirement in the form example

damianricobelli commented 4 months ago

Solved thanks to the fix in the example proposed by @abeisleem --> https://github.com/damianricobelli/shadcn-stepper/pull/6