Ticket #8582 (closed bug: duplicate)
.focus() fires attribute events, but doesn't fire binded events
| Reported by: | albertbrufau@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.next |
| Component: | unfiled | Version: | 1.5.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When a focus related event is binded to an element, it is fired when the element loses the focus via browser way (tab key, mouse click). But when it loses focus via .focus() to another element, it doesn't fire. However, if the event is defined on the attribute of the element, it fires in both cases.
I attach a complete test: Control1 fires change event when loses focus with mouse or tab key, but doesn't fire change event when pressing enter key (which executes a focus on #submitbutton). In the other hand, Control2 fires change event in both cases. I've tested this on jQuery 1.5.1 and 1.3.2 in the following browsers: Firefox 4, IE9 and Chrome, and there is the same issue.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TESTING</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
$(document).ready(function() {
if ($.browser.mozilla) {
$("input.data-entry").keypress (checkEnter);
} else {
$("input.data-entry").keydown (checkEnter);
}
$('#control1').bind('change', function(event){$('#result').html($(this).val());});
});
function checkEnter(event) {
if (event.keyCode == 13) {
$('#submitbutton').focus();
return false;
}
}
/* ]]> */
</script>
</head>
<body>
<form action="/" method="get">
<fieldset>
<input type="text" id="control1" name="control1" value="control1" class="data-entry" tabindex="1" /><br />
<input type="text" id="control2" name="control2" value="control2" class="data-entry" tabindex="2" onchange="$('#result').html($(this).val());"/><br />
<div id="result">- - -</div><br />
<input type="submit" id="submitbutton" />
</fieldset>
</form>
</body>
</html>
Change History
comment:1 Changed 2 years ago by dmethvin
- Status changed from new to closed
- Resolution set to duplicate
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
