You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically I want to build a reusable form component that will sometimes be displayed in a dialog, and sometimes displayed in a page.
I'd like to use dialog buttons for submit when included in a dialog, which requires the button to be external to formik form.
I've currently got the consumer creating a ref, and passing that into innerRef, and then in my button click handler, I just do something like:
fRef?.current.handleSubmit()
This all works, but I am genuinely curious if there is a better way to do this.
I've noticed that there is nothing to prevent submission of the form, so I was now looking to set disabled status on the external submit button until the form is deemed to be valid.
Note: I've been able to see isValid hanging off the current ref, but it seems to always be true, and I'd assume I cant bind disabled on the buttons to that, as the consumer doesn't know when that value changes.
EDIT: Is there a way we can validate in the typical ways, and communicate the state of the validity of the form to the formik consumer so I can dynamically disable/enable the submit button?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So basic details
Basically I want to build a reusable form component that will sometimes be displayed in a dialog, and sometimes displayed in a page.
I'd like to use dialog buttons for submit when included in a dialog, which requires the button to be external to formik form.
I've currently got the consumer creating a ref, and passing that into
innerRef
, and then in my button click handler, I just do something like:This all works, but I am genuinely curious if there is a better way to do this.
I've noticed that there is nothing to prevent submission of the form, so I was now looking to set disabled status on the external submit button until the form is deemed to be valid.
Note: I've been able to see isValid hanging off the current ref, but it seems to always be
true
, and I'd assume I cant bind disabled on the buttons to that, as the consumer doesn't know when that value changes.EDIT: Is there a way we can validate in the typical ways, and communicate the state of the validity of the form to the formik consumer so I can dynamically disable/enable the submit button?
Ideas/Advice?
Beta Was this translation helpful? Give feedback.
All reactions