#10845 closed bug (invalid)
preventDefault in keypress event cancel change event
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.1rc1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If i return false from keypress event or do a preventDefault, the change event when i leave text field is not called.
here is a simple example:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WrongPreventDefault.aspx.cs" Inherits="TPUsineV2.WrongPreventDefault" %> <!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<title></title> <script type="text/javascript" src="Scripts/jquery-1.7.min.js"></script> <script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#TextBox1").on('keypress.datetime', function (event) {
$(this).val('i processed') return false;
}).on('change.datetime', function (event) {
alert('change');
});
});
</script>
</head> <body>
<form id="form1" runat="server"> <div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div> </form>
</body> </html>
I've visually compiled your example and tried to create a test case:
http://jsfiddle.net/dmethvin/UpDLV/
From what I can tell though, this works as expected. Here's the W3C events spec:
http://www.w3.org/TR/DOM-Level-3-Events/#event-type-keypress
You've prevented the default action so the character typed by the user is not entered and there is no need for
change
event. You've also set the value *explicitly* in code using.val()
but that does not fire achange
event. Only user-initiated actions fire those events.