2

I want to be able to append text to the spinner on the 'spin' event. Here is what I currently have, but nothing is happening.

$( "#obj1, #obj2" ).spinner({
    min: 0,
    step: 5,
    spin: function( event, ui ) {
        $("#" + event.target.id).spinner("value", "Number " + ui.value);
    }
});

Anyone know what I'm doing wrong?

Jason Lipo
  • 751
  • 2
  • 11
  • 24

3 Answers3

1

Only with return false; worked for me:

$('#obj1').spinner({
        min: 2,
        max: 10,
        spin: function(event, ui) {
              $(this).spinner('option', 'min', 0);
              $(this).spinner('value', 0);
              $(this).spinner('option', 'min', 2);
              return false;
        }
});
bancer
  • 7,475
  • 7
  • 39
  • 58
0

Instead of using

$("#" + event.target.id).spinner("value", "Number " + ui.value);

try using

$(this).spinner("value", "Number " + ui.value);

Setting the value like that also triggers the "change" event.

carraua
  • 1,398
  • 17
  • 36
0

For future reference, this is the correct way to set value on spin:

$( "#obj1, #obj2" ).spinner({
        min: 0,
        step: 5,
        spin: function( event, ui ) {
              $( this ).spinner( "value", "Number " + 7 );
        }
});
d.raev
  • 9,216
  • 8
  • 58
  • 79