Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement multiple selects with jQuery UI Selectable

can anyone help me use the jquery ui selectable library to perform the following functions:

  • Allow a user to select multiple items with a mouse click
  • De-select an item if it is already selected with a mouse click
like image 531
HBCondo Avatar asked Dec 09 '10 07:12

HBCondo


2 Answers

This is worked around in another question, but I'm reposting here for anyone who finds this via google. If you bind the "mousedown" event in jQuery and set metaKey there (as if the user is holding the ctrl/cmd key), then when you call selectable, it will already be set.

$(".YOUR_SELECTOR_HERE").bind("mousedown", function(e) {
  e.metaKey = true;
}).selectable();
like image 187
Eric Skiff Avatar answered Oct 14 '22 17:10

Eric Skiff


Doesn't use Selectable but this will get you the behavior you want with the setup you already have:

instead of

$( "#selectable" ).selectable()

try

$(".ui-widget-content").click( function() {
    $(this).toggleClass("ui-selected");
});
like image 43
timbroder Avatar answered Oct 14 '22 16:10

timbroder