I am using jQuery UI selectable widget. I saw a solution at Is there a way to change event parameters in jQuery? to enable multiple selection (with mouse drag) which works fine. Now I am trying to get the similar feature to unselect multiple elements which doesn't work.
$('#selectlist').on("mousedown", function (e) {
e.metaKey = true; //multiple select true
//e.ctrlKey = true;
}).selectable({
filter: '.select-li',
selecting: function (event, ui) {
debugger;
//if ($(ui.selecting).hasClass('li-planned')) {
// $(ui.selecting).removeClass("ui-selecting");
//}
},
unselecting: function (event, ui) {
//if ($(ui.unselecting).hasClass('li-planned')) {
// $(ui.unselecting).removeClass("ui-unselecting").addClass('ui-selected');
//}
},
stop: function (event) {
//debugger;
//do some work here
}
})
I tried multiple options to achieve but so far I am not able to get it. Any help will be appreciated.
I've created a solution here and also added snippet in my answer. Here I've added a flag class to elements on select event to identify later which items were selected and then remove both
ui-selected
and flag class from them, which then make it unselected. I think that's what you're looking for.