thaya
thaya

Reputation: 15

how to use two stop event in jquery ui spinner

In the below code I need to execude show_error method with debounce (delay) and show_value method without delay.

Both methods needs in stop event only how to do it ?

$("#test").spinner({
 stop: function(event , ui){
 show_value();
  },
 stop: _.debounce(function(e, ui) {
      show_error();

    }, 300)
        });

Upvotes: 0

Views: 148

Answers (1)

blgt
blgt

Reputation: 8205

Call both functions in a single handler:

var debouncedStop = _.debounce(function(e, ui) {
      show_error();
}, 300);
$("#test").spinner({
 stop: function(event, ui){
     show_value();
     debouncedStop();
 }
});

Or bind them separately:

$("#test").spinner()
          .on("spinstop", function(event , ui) {
              show_value();
          })
          .on("spinstop", _.debounce(function(e, ui) {
              show_error();
          }, 300));

Upvotes: 0

Related Questions