updated slider refresh function with an extra param for preventing validation on its input Fixes #468

This commit is contained in:
John Bender 2011-01-24 23:38:50 -08:00
parent 3df24fab6d
commit 442e4b19b0
2 changed files with 30 additions and 8 deletions

View file

@ -77,6 +77,9 @@ $.widget( "mobile.slider", $.mobile.widget, {
self.refresh( ((cType == 'input') ? parseFloat(control.val()) : control[0].selectedIndex), true );
})
.keyup(function(){ // necessary?
self.refresh( ((cType == 'input') ? parseFloat(control.val()) : control[0].selectedIndex), true, true );
})
.blur(function(){
self.refresh( ((cType == 'input') ? parseFloat(control.val()) : control[0].selectedIndex), true );
});
@ -131,7 +134,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
this.handle
.bind('keydown', function( event ) {
var valuenow = $( this ).attr( "aria-valuenow" ),
index;
index;
if ( self.options.disabled ) {
return;
@ -193,7 +196,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
this.refresh();
},
refresh: function(val, isfromControl){
refresh: function(val, isfromControl, preventInputUpdate){
if ( this.options.disabled ) { return; }
var control = this.element, percent,
@ -248,13 +251,15 @@ $.widget( "mobile.slider", $.mobile.widget, {
}
}
// update control's value
if ( cType === "input" ) {
control.val(newval);
} else {
control[ 0 ].selectedIndex = newval;
if(!preventInputUpdate){
// update control's value
if ( cType === "input" ) {
control.val(newval);
} else {
control[ 0 ].selectedIndex = newval;
}
if (!isfromControl) { control.trigger("change"); }
}
if (!isfromControl) { control.trigger("change"); }
},
enable: function(){

View file

@ -62,6 +62,23 @@
});
});
test( "slider should validate input value on blur", function(){
var slider = $("#range-slider-up");
slider.focus();
slider.val(200);
same(slider.val(), "200");
slider.blur();
same(slider.val(), slider.attr('max'));
});
test( "slider should not validate input on keyup", function(){
var slider = $("#range-slider-up");
slider.focus();
slider.val(200);
same(slider.val(), "200");
slider.keyup();
same(slider.val(), "200");
});
// generic switch test function
var sliderSwitchTest = function(opts){