Opened 11 years ago

Last modified 10 years ago

#8150 open feature

Selectable Stop Event Fires Multiple Times While Holding Ctrl

Reported by: Ariesto Owned by:
Priority: minor Milestone: 2.0.0
Component: ui.selectable Version: 1.8.18
Keywords: Cc:
Blocked by: Blocking:

Description

To reproduce this enhancement: http://jsfiddle.net/FkMtq/18/

Hold ctrl and click on Item 1, and Item 7. Then let control go. You will see the stop event fired twice instead of one time.

Currently the stop event triggers on click. This works with contiguous selection, but selectable is supposed to support Ctrl/ metakey holding as well. In cases where you hold the Ctrl key the stop event occurs multiple times, not once the Ctrl key is let go. In my mind this is counter-intuitive since I am looking for an event that signals the completion of the selection.

Half of the fix is to wrap the stop trigger in an 'if statement' to check if the ctrl key is pressed like so: if (!event.metaKey && !event.ctrlKey) { this._trigger("stop", event)}

The second half is on .KeyUp then broadcast the event.

I haven't been able to figure out how to access the .Keyup event inside the selectable.js (I'm new to this).

Change History (5)

comment:1 Changed 11 years ago by Ariesto

Here is the solution that works for me:

I add a new option: triggerOnce: false

Then I change the stop event trigger with the two if statements below:

        //Cases where the ctrl button is not pressed
        if (!event.metaKey && !event.ctrlKey) { this._trigger("stop", event);}

        //Cases where the ctrl button is pressed
        if (options.triggerOnce == false) {$(document).keyup(function() {self._trigger("stop", event); }); options.triggerOnce = true;}

In my local code I reset the triggerOnce and it works like a charm. I am applying the .keyup to the document because .keyup requires focus and I was having trouble finding the element.

I'm sure others will want to refactor/ probably have issue with changing the stop event logic. Also, logically you would change the start event to operate the same way, but in my case I don't need to so I have not.

comment:2 Changed 11 years ago by Ariesto

I tried making a fork. Dunno how well it will work:

https://github.com/jquery/jquery-ui/pull/608

comment:3 Changed 11 years ago by Scott González

Type: enhancementfeature

comment:4 Changed 10 years ago by Scott González

Milestone: 1.9.02.0.0

comment:5 Changed 10 years ago by Jörn Zaefferer

Status: newopen

Consider for redesign.

Note: See TracTickets for help on using tickets.