bootstrap-slider change max value
You just need to apply setValue
after you'v changed $('#slider').data('slider').max
$slider = $('#slider');
// Get current value
var value = $slider.data('slider').getValue();
// should be:
// var value = $slider.slider('getValue');
// but it doesn't work
// Change max
$slider.data('slider').max = 13;
// Apply setValue to redraw slider
$slider.slider('setValue', value);
http://jsfiddle.net/23aPK/
I had the same problem and the best solution I found was to destroy the slider and recreate it whenever I needed to change the range values. It's a little tricky because: 1) removing the slider also removes the original anchor tag; and 2) you need to save the css width of the old slider and use it for the new one.
Here's a simplified version of the code I used. If you have more than one slider on your page, then you'll need to be careful and only delete the one you need to update.
HTML:
<div id="sliderDiv">
<input id="mySlider" type="text" data-slider-tooltip="show"/>
</div>
Javascript:
//Call this function to create the slider for the first time
function createSlider(minRange, maxRange){
$('#mySlider').slider({
min: minRange,
max: maxRange,
value: defaultValue
}).on('slideStop', handleSliderInput);
}
//Call this function to destroy the old slider and recreate with new range values
function changeSliderRange(newMin, newMax){
//Save old slider's css width
var oldSliderWidth = $("#mySlider").css("width");
//remove the old slider
$(".slider").remove();
//Recreate slider anchor tag with saved width value
$("#sliderDiv").after("<input id='mySlider' type='text' style='display: none; width: "+ oldSliderWidth + ";'/>");
//Now recreate the slider
createSlider(newMin, newMax);
}
You need to call the refresh method. The following code does the trick:
$("#slider").slider('setAttribute', 'max', maxVal);
$("#slider").slider('setAttribute', 'min', minVal);
$("#slider").slider('refresh');
I struggled getting this to work with various examples and eventually sorted it with this syntax, which I added into my function where needed.
strMin=3;
strMax=5;
$("#myslider").data('slider').min=strMin;
$("#myslider").data('slider').max=strMax;
$("#myslider").data('slider').value="[" + strMin + "," + strMax + "]";
$("#myslider").data('slider').setValue([strMin,strMax],true);