Disabling ctrl-click on jquery ui selectable
Asked Answered
L

3

9

I was wondering if there is an option on the jQuery UI Selectable that will let me disable the Ctrl+Click, but still keep the draggable for the multiple selection. On my project I want to be able for people to select multiples, but only by dragging, not by Ctrl+clicking.

If there isn't, does anyone know a way I can achieve this?

Any information would be really helpful! :) Thanks!!!

Lathery answered 1/4, 2011 at 19:25 Comment(0)
C
12

Selectable uses the metaKey flag to do multi-select, so you can bind metaKey to be false on the mousedown before calling selectable. Then Ctrl+click will always be off. Make sure to bind before calling selectable though.

$('#selectable').bind("mousedown", function (e) {
            e.metaKey = false;
 }).selectable()

jsFiddle here

Creamer answered 1/4, 2011 at 19:28 Comment(2)
Thank You So Much!! :) I've been searching for this for days. hehe.Lathery
Just in case someone (like me) get's here and is trying to implement the opposite (allow multi select without ctrl) - do e.metaKey = true;Matrilineal
C
3

There is another usage of this good solution above - if you want to be able to just use your mouse click to do all the selecting/unselecting, without the need for holding the Ctrl for multiselects or for unselects - just always set the e.metaKey from EvilAmarant7x's example to true. It was exactly what I needed.

Edit: apparently someone already thought of that: Implement multiple selects with jQuery UI Selectable :)

Crupper answered 11/4, 2011 at 19:44 Comment(0)
G
2
$("#selectable").on("selectablestart", function (event, ui) {
event.originalEvent.ctrlKey = false;
});
Goldeneye answered 18/4, 2014 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.