Created
October 13, 2021 22:11
-
-
Save kerrishotts/335e2413ccd6f3a710387e2f76468b2f to your computer and use it in GitHub Desktop.
Buggyfill for sp-textfield not firing `change` event
This file contains hidden or 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 () { | |
if(require("uxp").versions.uxp.startsWith("uxp-5.5.1")) { | |
let curField, curValue; | |
document.addEventListener("focus", evt => { | |
curField = evt.target; | |
curValue = curField.value; | |
}, true); | |
document.addEventListener("blur", evt => { | |
if (evt.target.tagName === "SP-TEXTFIELD") { | |
if (curField === evt.target) { | |
if (curValue !== evt.target.value) { | |
const changeEvent = new Event("change", { | |
bubbles: true | |
}); | |
evt.target.dispatchEvent(changeEvent); | |
} | |
} | |
} | |
}, true); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment