bmvantunes / youtube-2020-june-multi-step-form-formik

A repository with a multi-step form using Formik, Yup and Material-UI
https://youtu.be/l3NEC4McW3g
MIT License
101 stars 68 forks source link

How to define a field value? #6

Closed 3runoDesign closed 4 years ago

3runoDesign commented 4 years ago

I can't set a field value after an onBlur.

something like:

const handleCEP = (ev, props) => {
  props.handleChange(ev);

  fetch(`https://viacep.com.br/ws/77807060/json/`)
    .then((res) => res.json())
    .then((data) => {
      props.setFieldValue("logradouro", data.logradouro);
    });
};
<Field
  name="cep"
  component={TextField}
  type="text"
  label="CEP"
  placeholder="Qual seu CEP?"
  variant="outlined"
  onBlur={(ev) => handleCEP(ev, props)}
  fullWidth
/>

Can you help me? Thank you!

bmvantunes commented 4 years ago

answered in #5