I have some code basically like the following
.on("keyup", "input", function (e) {
this.value = utils.formatNumber(this.value);
})
.on("change", "input", function(e) {
expensiveFunctionThatUpdatesView();
})
As it is, the values are formatted correctly as the user types, but the when the user tabs or clicks its way out of the input field, the onChange event is not triggered (hence the view is not updated). If I comment out the body of the keyup event handler function everything works as intended (except formatting). Why is this so?
AFAIK, there are two conditions that need to be satisfied for an onchange event to be triggered:
- One must have entered the control/input field by something that has triggered an onfocus event (storing the old value).
- The value that was present on focus is different from the one that exists on "exit"/blur
BTW, I tried changing the code to "blur", but that is not triggered either if I format the field. Using Chrome when testing this.