Skip to main content

Bug Tracker

Side navigation

#10845 closed bug (invalid)

Opened November 21, 2011 04:30PM UTC

Closed November 21, 2011 05:58PM UTC

Last modified March 09, 2012 09:43PM UTC

preventDefault in keypress event cancel change event

Reported by: rpalbert@gmail.com 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>

Attachments (0)
Change History (1)

Changed November 21, 2011 05:58PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

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

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.