0

I'm trying to run an auto script that submits data. I have few validations check to get the buttons to popup in the UI, for that I'm firing the input events. Is there any way, we can check the EVENT is fired / completed? Here are few of the methods:

//For Dispacthing Events
function dipacthEvents() {
    return new Promise(async (res, rej) => {
        const event = new Event('input', {
            bubbles: false
        });
        const ip = new Event('input', {
            bubbles: false
        });
        await window.tinyMCE.triggerSave()
        await document.querySelectorAll('[ng-name = "CoreProperties-Key0"]')[0].dispatchEvent(event);
        await document.querySelectorAll('[ng-name = "CoreProperties-Name0"]')[0].dispatchEvent(ip);
        res("dipactched");
    })
}
//main
function createKey(key, value) {

    updateFields(key, value);
    dipacthEvents()
        .then(async (msg) => {
            console.log(msg)
            await updateClicks();
        })
}

updateClicks() have DOM elements manipulations for click buttons. How can I make sure click method runs after all the event are fired? Appreciate any help here!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • [Never pass an `async function` as the executor to `new Promise`](https://stackoverflow.com/q/43036229/1048572)! – Bergi Apr 08 '20 at 17:10
  • What's the environment for this code, plain in-browser DOM? `dispatchEvent` is synchronous. There is no need to `await` it. It won't return until all event handlers had run. Is there an actual problem you are experiencing with your code? `updateClicks` already should run after all events are done. – Bergi Apr 08 '20 at 17:13
  • Yes, it is in browser DOM(chrome- source snippets). I have tried without await for the events. But click method is resolving before all the events are done. – Praveen Kumar Apr 12 '20 at 18:37
  • What exactly do you mean by "*the events are done*"? What do the event handlers do? Please provide a [mcve]. – Bergi Apr 12 '20 at 21:10

0 Answers0