Reputation: 4128
I want to ensure the following very primitive behavior for selectable:
I am trying to build sort of a basket—when it opens up its content is displayed and some items are highlighted. Then user either selects more or deselect others, submits the form. That's all.
I fought with Selectable for quite some time and its a very smart piece of script, but I seem to be unable to achieve this basic requirements. When form is shown users need to hold the Ctrl key, otherwise already selected items get lost.
Upvotes: 4
Views: 3201
Reputation: 987
It is easiert to not use selectable at all:
$('ul > li').click(function() {
$(this).toggleClass('ui-state-highlight');
});
Upvotes: 4
Reputation: 43823
I answered something similar the other day that I think solves part 1 of your problem - How to select multiple items using mouse click?. This allows left click or lasso to select/deselect without the need for the Ctrl key.
However, looking over the demo, I created for that question, by adding
tolerance: 'fit'
to the selectable, it seems to disable selection via lasso which I think solves part 2 of your question.
Lastly, if you use a jQueryUI theme, you will also need to override the lasso style. The relevant theme rule is:
.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; }
and something like
.ui-selectable-helper { display:none }
should do it.
Upvotes: 3