I have some code that, when the user leaves an input box, checks for a valid date. If not, it sends an invalid date alert, wipes out the text, and resets the focus back to the box. Here's the code, after various simplifications:
The browser (FF 9.0.1) apparently executes the focus() method, and then happily goes and focuses wherever the user had planned to go. I'm reduced to the frightful hack of pausing for a millisecond before executing the focus method so whatever thread is changing the focus can finish doing so, thereby allowing me to change it back.
I have attempted using the change event as well, but that doesn't work either. Since it fires before blur, that's not surprising. I've tried all of the three commands I've commented out, with no luck.
Can someone give me a glimpse under the hood?
An unforeseen consequence of the information revolution has been the exponential propagation of human error.
Code:
$('#startDate').on('blur', function (event) {
if (!isDate(event.target.value)) { //isDate is a validation function, works fine
alert('Invalid Date');
event.target.value = '';
// setTimeout(function () { //the horror...the horror...
document.getElementById(event.target.id).focus();
// }, 1);
// event.preventDefault;
// event.stopImmediatePropagation;
// event.stopPropagation;
return false;
}
});
I have attempted using the change event as well, but that doesn't work either. Since it fires before blur, that's not surprising. I've tried all of the three commands I've commented out, with no luck.
Can someone give me a glimpse under the hood?
An unforeseen consequence of the information revolution has been the exponential propagation of human error.