Answer the question
In order to leave comments, you need to log in
How to change the value of another field in Formik?
Hello, please tell me how to change the value of another field in onChange () of the first field?
I'll show you with an example:
<form onSubmit={handleSubmit}>
<Typeahead
name="firstField"
onChange={firstField => {
setFieldValue("firstField", firstField);
}}
onInputChange={firstField => {
setFieldValue("firstField", firstField);
}}
options={data}
labelKey="key"
/>
<Typeahead
name="secondField"
onChange={secondField => {
setFieldValue({
secondField: secondField, //текущее поле менят свое значение
firstField: "testValue" //при этом первое не меняется
});
}}
onInputChange={secondField => {
setFieldValue("secondField", secondField);
}}
options={data}
labelKey="key"
/>
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question