Is there a way to set an iMask field's value programmatically? #1039
-
I'm building a form filling browser extension, and would like to select an input element by id and then set it's value. I've tried focusing and blurring, as well as dispatching keyboard events, but nothing seems to work properly. Has anyone had any luck with this? |
Beta Was this translation helpful? Give feedback.
Answered by
npearson72
May 12, 2024
Replies: 1 comment
-
Turns out it's not an iMask issue at all. Figured it out like so: const value = ...;
const inputEl = document.getElementById(...);
inputEl.focus();
await new Promise(resolve => {
inputEl.value = value;
inputEl.dispatchEvent(new Event('input', { bubbles: true }));
resolve();
});
inputEl.dispatchEvent(new Event('keyup', { bubbles: true }));
inputEl.blur(); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
npearson72
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out it's not an iMask issue at all. Figured it out like so: