We need to do a fair amount of extra plumbing in order to tell which button is clicked.
E.g. on a form with buttons for: Back, Save Application, and Continue
Any of these once clicked invokes Submit behavior. We want to show a loading indicator on one of the buttons, and disable the others. This is not easy.
We should be able to easily tell which button was clicked in order to display the proper UI
Perhaps isSubmitting could be supplemented with something like an actionBeingSubmitted field in order to easily know which button should get the loading indicator.
All users using more modern design techniques (displaying a loading indicator on an individual button).
We have this implemented by adding an additional form value, but it feels clunky and like we're reinventing the wheel on a more general problem.
Thanks for the consideration and the great library!
Agreed. This would be an awesome feature. Please consider.
@lukewlms Could you share how are you doing it right now? I am trying to do the same using submit buttons and I haven't had any luck
@drac94 I did something like this in one of my projects. It's a workaround but works fine
<Formik
initialValues={{
submitBttn: ''
}}
onSubmit={(values => {
console.log('Submit button: ', values.submitBttn);
})}
>
{(helpers) => {
return (
<form
onSubmit={helpers.handleSubmit}
onReset={helpers.handleReset}
>
<button
onClick={() => {
helpers.setFieldValue('submitBttn', 'type1')
}}
type="submit"
>
Submit type 1
</button>
<button
onClick={() => {
helpers.setFieldValue('submitBttn', 'type2')
}}
type="submit"
>
Submit type 2
</button>
</form>
)
}}
</Formik>
Most helpful comment
@drac94 I did something like this in one of my projects. It's a workaround but works fine