PDA

View Full Version : Suppress click when double click?



dbassett74
27 Jun 2010, 5:47 PM
I'm really struggling with this. In a desktop development environment, a click event will not occur if a double click event occurs. But with ExtJS, it seems that when double clicking, like on a TreeNode, the click event fires first, then the double click, then the click event one more time.

Is there anyway to override this behavior such that if a double click is detected, to suppress the pre and post click events from firing? It really should be like this anyways because you will typically assign different actions to a click and double click, and probably don't want both of those actions to occur at the same time.

Any help on this would be appreciated.

28 Jun 2010, 3:36 AM
It's not an "Ext JS" thing, but a web thing.

What you should do is setup a delayed task that is fired when clicked. For the double click event that click task should be canceled.

dbassett74
28 Jun 2010, 7:06 AM
It's not an "Ext JS" thing, but a web thing.

What you should do is setup a delayed task that is fired when clicked. For the double click event that click task should be canceled.

But what about the click even that also fires AFTER the double click event? Also, seems like a scheduled task is a bit of overkill. There must be some other way to accomplish this.

28 Jun 2010, 7:09 AM
not that I am aware of. Click and dbl click events have been an issue since JavaScript has been able to setup event listeners.

Take a look at this site: http://www.chipchapin.com/WebTools/JavaScript/example3-01.html

dbassett74
28 Jun 2010, 8:07 AM
Thanks, that was a real eye opener to the issue. Wow, seems like a hard issue to solve. What seems odd to me though is the fact that the event is initially coming from the OS, and somehow the OS (in my case, Windows) knows when I'm clicking or double clicking and doesn't fire both. So it seems that somehow the browser is getting around the OS somehow, which seems impossible since it is the OS that is doing all the instruction, isn't it? Weird...

dbassett74
28 Jun 2010, 8:12 AM
Actually, I stand corrected! I guess Windows DOES fire both the click and then double click events. Wow, I don't know why I have never run into an issue with this in a desktop application. Probably because you generally don't ever handle both of these events on the same object, for example, a Button would only be click, not double click, etc. So maybe I need to rethink how I'm building my web app a bit.

mschwartz
28 Jun 2010, 8:18 AM
It's not an "Ext JS" thing, but a web thing.

What you should do is setup a delayed task that is fired when clicked. For the double click event that click task should be canceled.

The only problem with this scheme is that the user can set the double click timeout for his OS and the JS doesn't know how long to set that delayed task...

28 Jun 2010, 8:18 AM
! I guess Windows DOES fire both the click and then double click events.
That's what I thought, but I'm no expert in the matter. :(

CrazyEnigma
28 Jun 2010, 12:44 PM
Actually, the two click events fire before the dblclick. It has to. It has to track how much of the clicks are close together.

This has been solved in another post about two weeks ago. Condor wrote a response on this.

You introduce a delay, and you introduce two boolean variables and delete each of them in the click response.

http://www.sencha.com/forum/showthread.php?100266-grid-with-both-headerdblclick-and-headerclick-events.&highlight=double+click+Condor