Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery selectable and right click

I am using a jquery selectable as shown below.

//Selectable Functionality
$(document).ready(function () {
    $("#Selectable_Positions").selectable({
        selected: function (event, ui) {
            dostuff();
        }
    })
})

It is working correctly however only left click will cause the select event to fire. I am trying to make it so that right click will as well. I have tried adding the code below and the alert fires but the selected item does not change.

$(document).ready(function () {
    $('#Selectable_Positions').mousedown(function () {
        $('#Selectable_Positions').trigger('selectableselected');
        alert('foo');
    })
})

How can I programatically change the selected item in the mousedown event function?


edit

Updated eventname as per Ian's suggestion below.

I have created a jsfiddle showing what I am trying to achieve and the triggered event not firing on right click. Does anybody know how to make this work? It would be greatly appreciated

http://jsfiddle.net/Jzjdm/

like image 228
Jamesla Avatar asked Oct 05 '22 06:10

Jamesla


1 Answers

The correct event name is "selectableselected". So use:

$('#Selectable_Positions').trigger('selectableselected');

Reference:

  • http://api.jqueryui.com/selectable/#event-selected
like image 73
Ian Avatar answered Oct 11 '22 12:10

Ian