I'm trying to autofill and trigger the 'Enter' keydown event on a textarea overdid by React.
The input autofill was resolved by this answer, thanks a lot to the author : https://stackoverflow.com/a/46012210/7260325
The only problem left is the 'Enter' key triggering. Standard JS methods available to achieve that seems to not work because of this React override. Anyone have a clue on how I can trigger these event ?
there is the code :
// I target my TextArea
var input_field = document.getElementsByClassName('MyTextArea')[0];
/*
* Fill Textarea value
* Tricks the React listener override
*/
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
nativeInputValueSetter.call(input_field, 'Toto And His friendssss');
var ev2 = new Event('input', { bubbles: true});
input_field.dispatchEvent(ev2);
// I try to fire the keydown 'Enter key' event
var ev3 = document.createEvent('KeyboardEvent');
// Send key '13' (= enter)
ev3.initKeyEvent(
'keydown', true, true, window, false, false, false, false, 13, 0);
input_field.dispatchEvent(ev3);
Thank you in advance for your help.