From 299d5c88b8bd60b23c03f73fd0dc8bf4d9cfb2a2 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Mon, 25 Oct 2010 17:32:08 +0200 Subject: [PATCH] Spinner: Fix value option initalization --- tests/unit/spinner/spinner.html | 1 + tests/unit/spinner/spinner_defaults.js | 2 +- tests/unit/spinner/spinner_options.js | 29 +++++++++++++++++++------- ui/jquery.ui.spinner.js | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/unit/spinner/spinner.html b/tests/unit/spinner/spinner.html index 954e82ea5..a9902a251 100644 --- a/tests/unit/spinner/spinner.html +++ b/tests/unit/spinner/spinner.html @@ -34,6 +34,7 @@
+
diff --git a/tests/unit/spinner/spinner_defaults.js b/tests/unit/spinner/spinner_defaults.js index a85891970..aa88fd649 100644 --- a/tests/unit/spinner/spinner_defaults.js +++ b/tests/unit/spinner/spinner_defaults.js @@ -12,7 +12,7 @@ var spinner_defaults = { numberformat: "n", page: 5, step: null, - value: 0 + value: null }; commonWidgetTests('spinner', { defaults: spinner_defaults }); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index 4e280ef6a..48fea3203 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -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"); }); diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js index a9238a738..70dd7adac 100644 --- a/ui/jquery.ui.spinner.js +++ b/ui/jquery.ui.spinner.js @@ -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();