Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10845 closed bug (invalid)

preventDefault in keypress event cancel change event

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1rc1
Keywords: Cc:
Blocked by: Blocking:


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) {





</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>

Change History (1)

comment:1 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

I've visually compiled your example and tried to create a test case:


From what I can tell though, this works as expected. Here's the W3C events spec:


The default action of the keypress event must be to dispatch a textinput event with the data attribute set to the value of the char attribute of the keypress event.

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 a change event. Only user-initiated actions fire those events.

Note: See TracTickets for help on using tickets.