By using :last or :first the selection is not the first selected but the first in order of li
This is the solution I managed:
HTML
<ol class="selectable">
<li class="ui-widget-content"
id="selectable_1"
value="1"
> First Selectable </li>
<li class="ui-widget-content"
id="selectable_2"
value="2"
> Second Selectable </li>
</ol>
In this code I gave the li an id and a value, thus making them available to the ui property of the selecting event
JAVASCRIPT
//A place to put the last one
var last_selected_value;
var last_selected_id;
$( ".selectable" ).selectable({
selecting: function(event, ui) {
//In the selection event we can know wich is the last one, by getting the id on
//the ui.selecting.property
last_selected_value = ui.selecting.value;
last_selected_id = ui.selecting.id;
},
stop: function(event, ui) {
//Here the event ends, so that we can remove the selected
// class to all but the one we want
$(event.target).children('.ui-selected').not("#" + last_selected_id)
.removeClass('ui-selected');
//We can also put it on a input hidden
$( "#roles_hidden" ).val(last_selected_value);
}
});