fix: autofill dispatches focus/blur/keyup/InputEvent for SPA frameworks
This commit is contained in:
@@ -100,12 +100,15 @@ _AUTOFILL_CONTENT_JS = r"""
|
||||
function setNativeValue(el, v) {
|
||||
if (!el) return false;
|
||||
if (el.value === v) return true;
|
||||
el.dispatchEvent(new FocusEvent('focus', { bubbles: true }));
|
||||
const proto = Object.getPrototypeOf(el);
|
||||
const desc = Object.getOwnPropertyDescriptor(proto, 'value') ||
|
||||
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value');
|
||||
if (desc && desc.set) desc.set.call(el, v); else el.value = v;
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
el.dispatchEvent(new InputEvent('input', { bubbles: true, data: v, inputType: 'insertText' }));
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
el.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true, key: v.slice(-1) }));
|
||||
el.dispatchEvent(new FocusEvent('blur', { bubbles: true }));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user