Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14669 closed bug (duplicate)

event.which failing for Shift + 7 (&) as Code 38 (Up Arrow)

Reported by: jon.hartmann@… Owned by: jon.hartmann@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

I have a simple batch of code that prevents up/down/tab/enter on a field:

if ($.inArray(event.which, [9, 38, 40, 13]) > -1) {
	event.preventDefault();

	return false;
}

However, if I type something like "example&" the code fires went I hit "&". If I put a break in there I can see that the event.which says its 38, and the other attributes of the event agree.

If I do other special characters such as or *, nothing happens, and if I hit the up arrow, the code fires as expected saying that it too is "38"

Change History (5)

comment:1 Changed 6 years ago by jon.hartmann@…

I've tested this in Chrome 31 and a recent FF with the same result. Running on a Windows 7 box... not sure what else would be relevant.

comment:2 Changed 6 years ago by jon.hartmann@…

Example inJSFiddle:

http://jsfiddle.net/6SNYa/

You can verify the problem there; I had a moment of panic where I thought the problem might be more complex than this.

comment:3 Changed 6 years ago by dmethvin

Owner: set to jon.hartmann@…
Status: newpending

Are you saying that the browser gives you the right value but jQuery isn't returning it? If so your test case should show the value you expected.Also, you shouldn't be listening to keypress. See #7183 and #10172.

comment:4 Changed 6 years ago by jon.hartmann@…

Status: pendingnew

You are right that it is the keypress event that is throwing the odd code. Weird... I'll review Monday and update if just removing keypress from this listener resolves this issue; I'm certain there was a reason why keypress was originally added since its common to avoid it.

http://jsfiddle.net/6SNYa/1/

Thanks!

comment:5 Changed 6 years ago by dmethvin

Resolution: duplicate
Status: newclosed

Duplicate of #7183.
Seems that way to me, I can reopen if not.

Note: See TracTickets for help on using tickets.