Skip to content

Commit

Permalink
Slider: Create clone of options.values during _create(). Fixed #8892 …
Browse files Browse the repository at this point in the history
…- Multiple Sliders have Conflict with options.values.
  • Loading branch information
dominicbarnes authored and scottgonzalez committed Dec 18, 2012
1 parent 9cbd4b4 commit 209443d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
31 changes: 28 additions & 3 deletions tests/unit/slider/slider_options.js
Expand Up @@ -143,8 +143,33 @@ test("step", function() {
// ok(false, "missing test - untested code is broken code.");
//});

//test("values", function() {
// ok(false, "missing test - untested code is broken code.");
//});
test("values", function() {
expect( 2 );

// testing multiple ranges on the same page, the object reference to the values
// property is preserved via multiple range elements, so updating options.values
// of 1 slider updates options.values of all the others
var ranges = $([
document.createElement("div"),
document.createElement("div")
]).slider({
range: true,
values: [ 25, 75 ]
});

notStrictEqual(
ranges.eq(0).data("uiSlider").options.values,
ranges.eq(1).data("uiSlider").options.values,
"multiple range sliders should not have a reference to the same options.values array"
);

ranges.eq(0).slider("values", 0, 10);

notEqual(
ranges.eq(0).slider("values", 0),
ranges.eq(1).slider("values", 0),
"the values for multiple sliders should be different"
);
});

})(jQuery);
5 changes: 3 additions & 2 deletions ui/jquery.ui.slider.js
Expand Up @@ -62,9 +62,10 @@ $.widget( "ui.slider", $.ui.mouse, {
if ( o.range === true ) {
if ( !o.values ) {
o.values = [ this._valueMin(), this._valueMin() ];
}
if ( o.values.length && o.values.length !== 2 ) {
} else if ( o.values.length && o.values.length !== 2 ) {
o.values = [ o.values[0], o.values[0] ];
} else if ( $.isArray( o.values ) ) {
o.values = o.values.slice(0);
}
}

Expand Down

0 comments on commit 209443d

Please sign in to comment.