formsy-react icon indicating copy to clipboard operation
formsy-react copied to clipboard

Synchronized fields

Open PiotrSzlagura opened this issue 3 years ago • 1 comments

Hi,

I would like to do something like this:

<input name="foo" />
<input name="foo" />

so that if user inputs something to first input, the second one fills the same automatically. What would be the best approach to do so in formsy controlled environment?

PiotrSzlagura avatar Feb 24 '22 13:02 PiotrSzlagura

2 inputs can't have the same name in HTML, therefore, formsy won't help you.

You can add other input & manage its value manually.

const MyApp = () => {
  const [value, setValue] = useState('');
  return (
    <Form>
      <Input
        name="foo"
        type="text"
        value={value}
        onChange={(e) => setValue(e.target.value)}
      />
      <Input name="foo_replicate" type="hidden" value={value} />
    </Form>
  );
};

felixmosh avatar Aug 24 '22 12:08 felixmosh

Going to close this as Felix answered it well. Re-open for further discussion.

rkuykendall avatar Oct 31 '22 21:10 rkuykendall