Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent the value from being updated in Jquery UI Spinner?

I don't want the value of my spinner to be updated when the user clicks on the up arrow. In the API says:

spin( event, ui )

Triggered during increment/decrement (to determine direction of spin compare current value with ui.value). Can be canceled, preventing the value from being updated.

But does not show an example of how to do it. I started a code like this:

var spinner = $( ".mySpinner" ).spinner({
    min: 0,
    spin: function( event, ui ) {
       //don't know what to do!
    }
});​

How can I cancel the spin event?

Can you help me? Thank you!

like image 675
Bagata Avatar asked Nov 06 '12 11:11

Bagata


1 Answers

Event cancellation in jQuery UI works the same way as for native DOM events.

You only have to call preventDefault():

var spinner = $( ".mySpinner" ).spinner({
    min: 0,
    spin: function( event, ui ) {
       // Cancel the spin event. The value will not be updated.
       event.preventDefault();
    }
});​

You can also return false from the handler, however this not only cancels the event but effectively stops its propagation to ancestor elements, as if stopPropagation() was called.

like image 157
Frédéric Hamidi Avatar answered Oct 27 '22 22:10

Frédéric Hamidi