question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manually handle the `onChange`?

See original GitHub issue

Bug, Feature, or Question?

Question/Feature?

Current Behavior

I have a custom dropdown component that returns on onChange just the array of selected options. I can’t find a way to make it play nicely with Formik.

Desired Behavior

I’d like to be able to manually handle the onChange call so that I can manually define which field is being modified and with what data.

Suggested Solutions

Something like:

handleChangeManually({
  name: 'something',
  value: [1, 2, 3]
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

25reactions
jaredpalmercommented, Feb 23, 2018

You can use setFieldValue('something', [1,2,3]) and wrap your input in a custom component.

6reactions
pastinepolentacommented, Sep 6, 2019

On my custom component I did:

onChange(val) {
    this.props.form.setFieldValue(this.props.name, val, true);
    this.props.form.setFieldTouched(this.props.name, true, false);
}

in order to trigger the change and also the validation, and the ErrorMessage shows up correctly

The onChange prop of the Form (Formik) though, does not seem to trigger

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I trigger an onchange event manually? [duplicate]
Hence I'm looking for a way to manually trigger this onchange event (which I guess should take care of checking the value difference...
Read more >
How can I trigger an onchange event manually in javascript?
Triggering the event manually − const e = new Event("change"); const element = document.querySelector('#test') element.dispatchEvent(e);.
Read more >
How to Handle Multiple Inputs with a Single onChange ...
Besides handling just one input, a single onChange handler can be set up to handle many different inputs in the form.
Read more >
SCR19: Using an onchange event on a select element ... - W3C
The objective of this technique is to demonstrate how to correctly use an onchange event with a select element to update other elements...
Read more >
Solved: How to call a text input's onChange action manuall...
This works fine by itself. However i am to call the onChange action on this text input so that a set of instructions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found