Side navigation
#7311 closed bug (worksforme)
Opened October 26, 2010 01:20AM UTC
Closed November 13, 2010 06:14PM UTC
Blur() callback is not issued if the focus is changed from form.submit() callback
Reported by: | alexalex | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | event | Version: | 1.4.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Make a simple page with two inputs - #first and #second - and a Submit button:
<form> <input id=first><br> <input id=second><br> <input type=submit> </form>
Then add this:
$(document).ready(function(){ $('form').submit(function(){ $('input#second').focus(); return false; }); $('#first').blur(function(){ alert('blur'); }); });
Then
- (a) open this page in FF 3.6 on Windows
- (b) click on first input to give it focus
- (c) hit Enter to submit the form
The #second gets the focus, but there is no 'blur' alert.
The demo page - http://swapped.cc/tmp/jquery-blur-quirk.html
Attachments (0)
Change History (3)
Changed October 26, 2010 04:02AM UTC by comment:1
_comment0: | [http://jsfiddle.net/snover/KHha9/ fiddle test case] \ \ So I am not actually sure this is a bug or not so I am leaving it open for review; you should probably be calling the focus function by doing $('input#second')[0].focus() which will ensure the appropriate events are dispatched. → 1288065752686722 |
---|---|
component: | unfiled → event |
keywords: | → needsreview |
milestone: | 1.5 |
priority: | undecided → low |
Changed October 26, 2010 04:29AM UTC by comment:2
Haaaa! That does solve the problem, thanks.
However the reason I logged it as a bug was that it was happening on Firefox only, but not on Chrome and IE.
Also, if you have a moment, can you explain how calling focus() on an array with one element is principally different from issuing the call directly for that element? It seems logical to assume that these two cases would yield the same result.
Changed November 13, 2010 06:14PM UTC by comment:3
keywords: | needsreview |
---|---|
resolution: | → worksforme |
status: | new → closed |
I think snover's point was that $().focus() does *two* things. It fires a "focus" event starting on the target element that bubbles up the DOM, and (if no handler returns false or calls preventDefault) calls the element's DOM focus method. In this case you only want the latter, and the former may be interfering.
fiddle test case
So I am not actually sure this is a bug or not so I am leaving it open for review; you should probably be calling the focus function by doing $('input#second')![0].focus() which will ensure the appropriate events are dispatched.