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');
6
  • i'm trying to trigger the jquery ui selection event. I have this widget in some tabs and I need to be able to re-trigger the selection event upon showing the tab. Commented Apr 4, 2011 at 16:45
  • sorry, made the question a bit more clear. Commented Apr 4, 2011 at 16:46
  • why dont u use all the callbacks that come with the plugin? Commented Apr 4, 2011 at 16:46
  • @ neal - I am. I am asking how to programmatically trigger this callback Commented Apr 4, 2011 at 16:48
  • have you tried "selectablestop"? Commented Apr 4, 2011 at 16:49

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

right, as shown in my example i'm using the stop callback. How do i trigger this event programatically? EX: $( '.selector' ).trigger('selectablestop');
hmmm. it CAN be done! thx much must be something wrong w/ my code.
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.

1 Comment

Hope this help new questions: For later versions of the jQuery UI library, we should use .data("ui-selectable") instead of .data("selectable")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.