Stop input events on input boxes?

Is there any way to stop events on input boxes (with conditions in actual code)? Any of this would work in a regular browser:

document.getElementById("myinput").addEventListener('keydown', (event) => {
    event.preventDefault();
    event.stopPropagation();
    return false;
});

document.getElementById("myinput").addEventListener('keyup', (event) => {
    event.preventDefault();
    event.stopPropagation();
    return false;
});

document.getElementById("myinput").addEventListener('input', (event) => {
    event.preventDefault();
    event.stopPropagation();
    return false;
});

I found a workaround, sort of, in another thread. But it’s not pretty.

document.addEventListener("input", evt => {
    const { target } = evt;
    if (target.tagName === "INPUT" && target.id == "myinput") {
        if (!is_valid_check_goes_here) {
            target.value = target.getAttribute("data-uxp-last-good-value") || "";
        }
        else {
            target.setAttribute("data-uxp-last-good-value", target.value.trim());
        }
    }
});