Open sandorvasas opened 4 years ago
I think easiest way to do this would be to circumvent Formik altogether. After all, Formik is a form validation + submission library. However, your callback is not bound to Formik.
const getSubmitHandler = isDraft =>
async (values) => ajax.post(isDraft ? 'your/api/save-draft' : 'your/api/submit', values);
const onSubmit = getSubmitHandler(false);
const onSaveDraft = getSubmitHandler(true);
const YourForm = () => <Formik onSubmit={onSubmit}>
{({ values }) => <button onClick={() => onSaveDraft(values)} />}
</Formik>
I've got field-level validation (validate prop) on a huge form, and have two submit buttons: Save as draft (no validation required), Submit (needs to execute validation). I found no easy way to do this. As I said it's a huge form and now it looks like I need to replace the way all fields are validated. It would be so much easier to just do something like
I know this is a duplicate, I found that many people brought this up, but being the library that advertises itself as 'without the tears'. Well, this lack of feature gives me tears.