baltimorecounty / react-baltcogo

1 stars 0 forks source link

Add function to set multiple formik fields at a time #103

Open martypowell opened 5 years ago

martypowell commented 5 years ago

There are places in the app that we set serveral formik fields at a time, see an example here, https://github.com/baltimorecounty/react-baltcogo/blob/bug-fixes/src/components/ServiceRequestForm.jsx#L128

We can create a FormikHelper function to pass either an object or an array to set field values, something like. We should also verify that formik doesn't already have something for this. Because maybe we don't even need to do this.


const setFieldValues = (props, fields) => {
  fields.forEach(field => {
    const { name, value } = field;
    props.setFieldValue(name, value);
  });
}
tmccoy529 commented 5 years ago

This has been partially implemented. Service Request Form was done but the others have not been. The utility has been created SetFieldValues in the FormHelpers. Example of use:

const fields = { NameFirst: NameFirst, NameLast: NameLast, Email: Email, Telephone: Phone };

            SetFieldValues(localProps, fields);

We should leave this open until all forms have been converted.

martypowell commented 5 years ago

This is good, I copied this new function and made on for setting fields as touched in the FormikHelper file. Probably where this should go eventually.

martypowell commented 5 years ago

@tmccoy529 i actually think this is done right?

tmccoy529 commented 5 years ago

@martypowell I have been updating pages as I come across them but have not set out to do just this refactor. Lets leave it open for now since I'm not totally sure all pages have been converted.

martypowell commented 5 years ago

Oh i think this issue was just to add the helper. I am fine with what you are saying though.