Created
January 21, 2022 15:40
-
-
Save jonniek/be5bb32129c4ed8789f9fdd0d95cf4e3 to your computer and use it in GitHub Desktop.
set input value from console reactively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setNativeValue(element, value) { | |
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set; | |
const prototype = Object.getPrototypeOf(element); | |
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; | |
if (valueSetter && valueSetter !== prototypeValueSetter) { | |
prototypeValueSetter.call(element, value); | |
} else { | |
valueSetter.call(element, value); | |
} | |
} | |
// set input value reactively | |
// setNativeValue(input, 'foo'); | |
// input.dispatchEvent(new Event('input', { bubbles: true })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment