Hey, im new to using formik and i just wanted to know if it was possible to do conditional field rendering. I need to show different questions depending on a select dropdown value. Doing this normally is quite easy i know. Just wanted to know if its possible to do it with Formik as im trying to create a multi step booking form and i want to use Formik to handle all my form state. 馃憤
Formik doesn't take control over rendering your inputs--that's why it's powerful. You are in complete control of all rendering logic.
This is true, but if you're using validationSchema, you'll also have put conditional logic in the schema (i.e. the value for key conditionalField should be required only if it's currently being displayed). Do you have a suggestion on a good way to handle this without duplicating code?
@pimlottc-gov I am also facing the same issue. If you have figured out something then do share your approach.
I believe conditionally showing a field by passing the Field a validate prop (instead of passing it to the Formik component) should work.
How about something to aid listing what fields are currently in the dom. Something like currentFields mentioned here.
I am still facing this issue, was anyone able to get around this? is the CurrentFields released as part of formik now @jaredpalmer ?
Most helpful comment
This is true, but if you're using validationSchema, you'll also have put conditional logic in the schema (i.e. the value for key
conditionalFieldshould be required only if it's currently being displayed). Do you have a suggestion on a good way to handle this without duplicating code?