Reputation: 117
I have created a custom spinner which appends a string after a number.
var percent = 5.5%;
$.widget("ui.pcntspinner", $.ui.spinner, {
_format: function(value){
return value + " %";
},
_parse: function(value){
return parseInt(value);
}
});
$("#spinner").pcntspinner().val(percent);
The spinner has two events attached to it i.e. focusout and spin. focusout works fine in first call too, but spin does not gets triggered at first time. Only after any other event has been triggered does the spin gets called. Any idea to solve this problem?
Upvotes: 0
Views: 674
Reputation: 117
Found the solution. I still don't understand though why spin was not getting triggered the first time but this helped -
var percent = 5.5%;
$.widget("ui.pcntspinner", $.ui.spinner, {
widgetEventPrefix: "spin",
_format: function(value){
return value + " %";
},
_parse: function(value){
return parseInt(value);
}
});
$("#spinner").pcntspinner().val(percent);
Upvotes: 0
Reputation: 7676
You are extending the widget so spin
won't work you need _spin
$.widget("ui.pcntspinner", $.ui.spinner, {
_format: function(value){
return value + " %";
},
_parse: function(value){
return parseInt(value);
},
_spin: function( event, ui ) {
alert('value updated by :' + ui);
if(validation){
var result = this._super( event, ui );
return result; //<-- important for generic functionality
}else
{
//returning nothing would make value not change
}
}
});
Upvotes: 1