I have an input.onkeydown
handler and I check input.value
after setTimeout(..0)
.
I expect input.value
to have the new value when the setTimeout
callback runs.
In all browsers except Firefox it does. In Firefox it's not always the case.
The code to check is:
<input id="input">
<script>
input.onkeydown = function() {
setTimeout(() => this.value = this.value.toUpperCase());
};
</script>
The demo: http://plnkr.co/edit/rZmiHdttSXNdpKkR8YbH?p=preview
As I uppercase the input value after setTimeout(..0)
, it should be uppercased always. But as said, in Firefox it's not.
Here's the demo video; the first few seconds demonstrate the problem: https://jmp.sh/9XSROQ2
The relevant spec part is https://dom.spec.whatwg.org/#concept-event-dispatch.
Am I not getting something, or is this a long-standing bug in Firefox?
P.S. If I add console.log
in setTimeout
, I sometimes see the old value.
P.P.S. The purpose of this question is to know if I understand setTimeout
correctly or not. I'm familiar with a variety of ways to uppercase input
; please do not suggest oninput
, requestAnimationFrame
, or such.