jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.96k stars 2.79k forks source link

Yup validation on FieldArray of different input types #1814

Open zhhjoseph opened 5 years ago

zhhjoseph commented 5 years ago

Hello,

Still relatively new to Formik. I'm using FieldArray to render different types of input fields. An example payload would be an array of objects like below. Filter_type would determine what kind of input field (1 =default, 2 = email, 3 = number...). (Number, email, date, regular text). How would I create a Yup schema to validate the value type for the different types inputs?

{
custom_field_id: 60
field: 30
filter_type: 3
label: "Some number label"
value: "1234"
}
<FieldArray
           name="custom_fields"
           render={arrayHelpers => (
               <>
                   {values.custom_fields.map((fields, index) => (
                       <div key={index}>
                           <InputField
                              name={`custom_fields[${index}].value`}
                              placeholder={
                              fields.value ? fields.value : ""
                              }
                              title={fields.label}
                              />
                         </div>
                       ))}
                 </>
                        )}
 />

Thanks a lot!

RRicardotj commented 4 years ago

I have the same issue