Spinner: Fix value option initalization

This commit is contained in:
jzaefferer 2010-10-25 17:32:08 +02:00
parent 1be2a79076
commit 299d5c88b8
4 changed files with 26 additions and 10 deletions

View File

@ -34,6 +34,7 @@
<div id="qunit-fixture">
<input id="spin">
<input id="spin2" value="2">
</div>
</body>

View File

@ -12,7 +12,7 @@ var spinner_defaults = {
numberformat: "n",
page: 5,
step: null,
value: 0
value: null
};
commonWidgetTests('spinner', { defaults: spinner_defaults });

View File

@ -157,15 +157,30 @@ test("step", function() {
});
test("value", function() {
expect(2);
el = $('#spin').spinner({ value: 100 });
test("value, default, specified in markup", function() {
var el = $('#spin2').spinner();
equals(el.val(), 2, "starting value");
});
test("value, default, nothing specified", function() {
var el = $('#spin').spinner();
equals(el.val(), 0, "starting value");
});
test("value, override", function() {
var el = $('#spin').spinner({ value: 100 });
equals(el.val(), 100, "starting value");
});
test("value, override markup", function() {
var el = $('#spin2').spinner({ value: 100 });
equals(el.val(), 100, "starting value");
});
test("value, override later", function() {
var el = $('#spin').spinner();
equals(el.val(), 0, "starting value");
el.spinner('option', 'value', 1000);
equals(el.val(), 1000, "value option changed and set as current value");
});

View File

@ -29,11 +29,11 @@ $.widget('ui.spinner', {
numberformat: "n",
page: 5,
step: null,
value: 0
value: null
},
_create: function() {
this.value(this.element.val() || this.options.value);
this.value(this.options.value !== null ? this.options.value : this.element.val());
this._draw();
this._mousewheel();
this._aria();