score:1

Accepted answer

you can rewrite the field component for address accordingly.

<field name="address">
 {({
    field, // { name, value, onchange, onblur }
 }) => {
   values.address = values.mainaddress;
   return (
     <div>
        <input
           {...field}
           type="text"
           placeholder="address"
         />
      </div>
    );
  }}
</field>

here we are setting the value of address field to values.mainaddress if setadress checkbox is checked else we let formik value to fill it.

here is the working codesandbox code - https://codesandbox.io/s/fervent-tereshkova-sro93?file=/index.js

score:1

formik also provides values object you could use that for updating address value same as mainaddress. just provide name attribute to both input fields then assign like this - props.values.address = {...props.values.mainaddress}


Related Query

More Query from same tag