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.

onChange fires when value is changed programatically

See original GitHub issue

onChange is called when the Codemirror component receives a new value when rendering.

Test case: https://gist.github.com/insin/9e507894f3858028c7e5 Live version: http://bl.ocks.org/insin/raw/9e507894f3858028c7e5/

Every call to onChange is alert()-ed, Clicking the “Change value” button changes the value in the component’s state.

Just got bit by this using Redux, as updating some state which was being passed to Codemirror resulted in another dispatch firing via onChange, resulting in old state being retained. Worked around it myself by having onChange check if it received the same value as was being used for rendering, but is this behaviour something that’s possible to control, or it is a consequence of how Codemirror itself is implemented?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
atis--commented, Dec 6, 2015

The example doesn’t really work for me (some errors in the console). However, the change event from CodeMirror instance has a second argument which describes the change. If value comes from setValue() call, then change.origin == 'setValue', so I think that may be used to differentiate between the changes.

0reactions
scnirocommented, Jun 2, 2017

Hey all. I too was struggling with some related issues and decided to roll another wrapper for this at react-codemirror2. No external deps, state free, and works well for my use case. Please give it a look if you are feeling adventurous. I’d like to actively maintain it moving forward. I’m also looking for suggestions to craft it in the best fashion moving forward, so feel free to open up an issue with any wants/tips/etc you may want. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I programmatically force an onchange event on an ...
This technique only works if the change handler was attached by setting "onchange". It does not generate a 'real' event that triggers w3c...
Read more >
Programatically changing input value does not fire Onchange ...
Whenever the value is changed, on change event should be fired irrespective of the way the value was changed.
Read more >
How to fire "onchange" programmatically ? - MSDN - Microsoft
The onchange-event only fires when the user changes the value of a textbox. When the value of this textbox has been changed programmatically...
Read more >
Simulate React On-Change On Controlled Components
Manually trigger onChange when component is updated programmatically ... in React now dedupe's change events so they don't fire more than once per...
Read more >
Onchange event gets fired when value is set programmatically...
You may put below lines to overwrite existing funcationality of your control. var cntr=Xrm.Page.getControl("<your control Id>");. cntr.setAttribute("onchange", ...
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