1

EDIT:

the jQuery UI selectable widget has a callback built into it, stop, I need to know how to trigger this event programmatically.


(this was poorly worded) I've attached an event listener to the jQuery UI Selectable Widget. How can I programmatically trigger the stop event?


Ex Selectable:

$("table").selectable({
  filter: "tr",
  stop: function(){
    //do stuff
  }
});

// Various attempts at triggering the stop event
// one
$("table .ui-selected").click();

// two
$("table .ui-selected").select();

// three
$("table .ui-selected").trigger("click");

// shot in the dark 1
$("table").selectable('widget').trigger('stop');

// Shot in the dark 2
$("table").trigger('stop');

// really long shot in the dark
$("table").selectable('widget').call('stop');

Further Attempts

// selectablestop event

$("#table").selectable('widget').trigger('selectablestop');

$("#table .ui-selected").trigger('selectablestop');
Derek Adair
  • 21,846
  • 31
  • 97
  • 134

2 Answers2

12

If you want to trigger the event outside of the control you can simply call .trigger(). This assumes you are using the .bind() and not the anonymous stop:function() in options.

$("#selectable").selectable({});
$("#selectable").bind("selectablestop", function(event) {
    $("body").append("<h1>did selectablestop</h1>");
});
$(":button").click(function() {
    $('#selectable').trigger('selectablestop');
});

Code example on jsfiddle.

Edit

Another way would be to retrieve the stop: option value (which would be the function)

var s = $('#selectable').selectable( "option" , "stop"); 
s(); //call the function.

Code example on jsfiddle.

Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
4

I ended up doing this, found at How to programmatically select selectables with jQuery UI?

 $('#selectable').data("selectable")._mouseStop(null);

This will trigger the mouse stop event and execute the binded stop function on the selectable. If there's a way to trigger the stop in a more elegant way, I would love to see.

Community
  • 1
  • 1
Geert
  • 41
  • 1
  • 3
    Hope this help new questions: For later versions of the jQuery UI library, we should use .data("ui-selectable") instead of .data("selectable") – Jorge Nunez Newton Apr 01 '15 at 16:02