Input Listener
Usage
The input listener actually renders a Field
component from react-final-form with the same input name that the field that we want to change and uses the onChange
function to update its value.
import { Form } from 'react-final-form';
import { TextField } from '@comparaonline/ui-form-fields';
import { InputListener } from '@comparaonline/ui-input-listener';
const onSubmit = () => undefined;
<Form onSubmit={onSubmit}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<TextField
name="inputA"
label="Placa"
/>
<TextField
name="inputB"
label="Placa"
/>
<InputListener field="inputA" when={value => value === 'foo'} set="inputB" to={new Promise(resolve => resolve('new value'))} />
</form>}
</Form>;