Skip to content

Instantly share code, notes, and snippets.

@adambray
Created July 3, 2018 19:59
Show Gist options
  • Save adambray/cfb0cf15fce03c7500fab3f7967fcc38 to your computer and use it in GitHub Desktop.
Save adambray/cfb0cf15fce03c7500fab3f7967fcc38 to your computer and use it in GitHub Desktop.
function setInputValue(id, value) {
const input = document.getElementById(id);
const lastValue = input.value;
input.value = value;
// react 16 hack
let tracker = input._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
input.dispatchEvent(new Event('input', {'bubbles': true, 'cancelable': true}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment