Spinner: this.options._decimals -> this._decimals

decimal test
This commit is contained in:
Chi Cheng 2008-08-19 15:52:35 +00:00
parent 62ed7d0388
commit bf1d243ce7
2 changed files with 29 additions and 12 deletions

View File

@ -135,7 +135,7 @@ test("keydown on input with options", function() {
el.simulate("keydown",{keyCode:$.simulate.VK_UP})
.simulate("keyup",{keyCode:$.simulate.VK_UP});
equals(el.val(), 60, "Stepping 10 on 50");
equals(el.val(), 60, "stepping 10 on 50");
el.simulate("keydown",{keyCode:$.simulate.VK_END})
.simulate("keyup",{keyCode:$.simulate.VK_END});
@ -160,7 +160,7 @@ test("currency and decimal options", function() {
el.simulate("keydown",{keyCode:$.simulate.VK_UP})
.simulate("keyup",{keyCode:$.simulate.VK_UP});
equals(el.val(), "$0.30", "Stepping 0.30");
equals(el.val(), "$0.30", "stepping 0.30");
el.simulate("keydown",{keyCode:$.simulate.VK_END})
.simulate("keyup",{keyCode:$.simulate.VK_END});
@ -180,6 +180,27 @@ test("currency and decimal options", function() {
equals(el.val(), "-$14.00", "keydown 120 times");
});
test("decimal options", function() {
expect(3);
el = $("#spin").spinner({ currency:false, incremental:false, stepping:0.7 });
equals(el.val(), "0.0", "start number");
el.simulate("keydown",{keyCode:$.simulate.VK_DOWN})
.simulate("keyup",{keyCode:$.simulate.VK_DOWN});
equals(el.val(), "-0.7", "stepping 0.7");
for ( var i = 1 ; i<=11 ; i++ ) {
el.simulate("keydown",{keyCode:$.simulate.VK_UP});
}
el.simulate("keyup",{keyCode:$.simulate.VK_UP});
equals(el.val(), "7.0", "keydown 11 times");
});
@ -235,19 +256,19 @@ test("mouse click on buttons", function() {
$(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
equals(el.val(), 1, "Mouse click to up");
equals(el.val(), 1, "mouse click to up");
$(".ui-spinner-up").trigger("dblclick");
equals(el.val(), 2, "Mouse double click to up");
equals(el.val(), 2, "mouse double click to up");
$(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
equals(el.val(), 1, "Mouse click to down");
equals(el.val(), 1, "mouse click to down");
$(".ui-spinner-down").trigger("dblclick");
equals(el.val(), 0, "Mouse double click to down");
equals(el.val(), 0, "mouse double click to down");
});

View File

@ -14,17 +14,13 @@
$.widget('ui.spinner', {
_init: function() {
if($.data(this.element[0], 'spinner')) return;
// check for decimals in steppinng and set _decimals as internal (needs cleaning up)
var decimals = 0;
if (this.options.stepping.toString().indexOf('.') != -1) {
var s = this.options.stepping.toString();
decimals = s.slice(s.indexOf('.')+1, s.length).length;
this._decimals = s.slice(s.indexOf('.')+1, s.length).length;
}
$.extend(this.options, {
_decimals: decimals
});
//Initialize needed constants
var self = this;
@ -200,7 +196,7 @@ $.widget('ui.spinner', {
this.element[0].value = (
this.options.currency ?
$.ui.spinner.format.currency(newVal, this.options.currency) :
$.ui.spinner.format.number(newVal, this.options._decimals)
$.ui.spinner.format.number(newVal, this._decimals)
);
},