-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Slider: Fix to restrict handle values when set programmatically. #1479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,4 +161,53 @@ test( "values, multi step", function() { | |
element.slider( "destroy" ); | ||
} ); | ||
|
||
test( "values", function() { | ||
expect( 12 ); | ||
|
||
var element = $( "<div></div>" ).slider( { | ||
range: true, | ||
min: 10, | ||
max: 100, | ||
step: 1 | ||
} ); | ||
|
||
element.slider( "values", [ 20, 90 ] ); | ||
deepEqual( element.slider( "values" ), [ 20, 90 ], "Values (array) - get value for all handles" ); | ||
|
||
element.slider( "values", [ 0, 200 ] ); | ||
deepEqual( element.slider( "values" ), [ 10, 100 ], "Values (array) - restricted min and max" ); | ||
|
||
element.slider( "values", 0, 50 ); | ||
equal( element.slider( "values", 0 ), 50, "Values (index,value) - set first handle" ); | ||
|
||
element.slider( "values", 1, 75 ); | ||
equal( element.slider( "values", 1 ), 75, "Values (index,value) - set second handle" ); | ||
|
||
element.slider( "values", 0, 5 ); | ||
equal( element.slider( "values", 0 ), 10, "Values (index,value) - 1st handle restricted properly, against min" ); | ||
|
||
element.slider( "values", 0, 90 ); | ||
equal( element.slider( "values", 0 ), element.slider( "values", 1 ), "Values (index,value) - 1st handle restricted properly, against 2nd handle" ); | ||
|
||
element.slider( "values", 1, 110 ); | ||
equal( element.slider( "values", 1 ), 100, "Values (index,value) - 2nd handle restricted properly, against max" ); | ||
|
||
element.slider( "values", 1, 40 ); | ||
equal( element.slider( "values", 1 ), element.slider( "values", 0 ), "Values (index,value) - 2nd handle restricted properly, against 1st handle" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same change here, use an explicit value. |
||
|
||
element.slider( "values", [ 50, 75 ] ); | ||
|
||
element.slider( "values", [ 0, 75 ] ); | ||
deepEqual( element.slider( "values" ), [ 10, 75 ], "Values (array) - Setting both handles - against min" ); | ||
|
||
element.slider( "values", [ 0, 90 ] ); | ||
deepEqual( element.slider( "values" ), [ 10, 90 ], "Values (array) - 1st handle restricted properly, against 2nd handle" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exactly the same as the previous assertion, and the message is wrong. |
||
|
||
element.slider( "values", 1, 110 ); | ||
deepEqual( element.slider( "values" ), [ 10, 100 ], "Values (array) - 2nd handle restricted properly, against max" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've already asserted this on L125. |
||
|
||
element.slider( "values", [ 75, 50 ] ); | ||
deepEqual( element.slider( "values" ), [ 75, 75 ], "Values (array) - Setting both handles - 2nd Handle resets to 1st" ); | ||
} ); | ||
|
||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,18 +238,34 @@ test( "step", function() { | |
//}); | ||
|
||
test( "values", function() { | ||
expect( 2 ); | ||
expect( 6 ); | ||
|
||
// 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 ] | ||
} ); | ||
document.createElement( "div" ), | ||
document.createElement( "div" ) | ||
] ).slider( { | ||
range: true, | ||
values: [ 25, 75 ] | ||
} ), | ||
element = $( "<div></div>" ).slider( { | ||
range: true, | ||
min: 10, | ||
max: 100, | ||
step: 1, | ||
values: [ 15, 1 ] | ||
} ); | ||
|
||
ranges = $( [ | ||
document.createElement( "div" ), | ||
document.createElement( "div" ) | ||
] ).slider( { | ||
range: true, | ||
values: [ 25, 75 ] | ||
} ); | ||
|
||
notStrictEqual( | ||
ranges.eq( 0 ).slider( "instance" ).options.values, | ||
|
@@ -264,11 +280,24 @@ test( "values", function() { | |
ranges.eq( 1 ).slider( "values", 0 ), | ||
"the values for multiple sliders should be different" | ||
); | ||
|
||
deepEqual( element.slider( "values" ), [ 15, 15 ], "handles restricted properly when set programmatically - 2nd handle reset" ); | ||
|
||
element.slider( "option", "values", [ 0, 200 ] ); | ||
deepEqual( element.slider( "values" ), [ 10, 100 ], "option values - restricted min and max" ); | ||
|
||
element.slider( "option", "values", [ 15, 1 ] ); | ||
deepEqual( element.slider( "values" ), [ 15, 15 ], "option values - restricted 2nd Handle" ); | ||
|
||
element.slider( "option", "values", [ 15, 15 ] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is effectively a no-op and should be removed. |
||
element.slider( "option", "values", [ 25, 15 ] ); | ||
deepEqual( element.slider( "values" ), [ 25, 25 ], "option values - restricted 2nd Handle" ); | ||
|
||
} ); | ||
|
||
test( "range", function( assert ) { | ||
expect( 32 ); | ||
var range; | ||
var element,range; | ||
|
||
// Min | ||
element = $( "<div></div>" ).slider( { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that you're trying to show that the handles are matching, but I'd prefer an explicit value for the expected value.