Reputation: 2491
Slider before resetting is at this position: (both thumb and color are at proper position)
Before Reset:
Html
<input id="xyzslider" class="mdl-slider mdl-js-slider" type="range" min="0.0" max="1.0" value="0.0" step="0.05" tabindex="20">
Jquery
$("#xyzslider").val(value);
After Reset:
Here is my problem. The slider thumb is reset to the minimum value but the color value represented by the slider is still at 0.6.
After this i reset the slider in the following way.
Jquery
$("#xyzslider").val(minValue);
My code is below. What could be the issue here? Why is the slider color value not getting reset? Any help would be invaluable.
$("#xyzslider").val(0.6);
$("#clickme").click(function() {
$("#xyzslider").val(0.0);
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<br>
<input type="button" id="clickme" value="Click Me To Reset Slider">
<input id="xyzslider" class="mdl-slider mdl-js-slider" type="range" min="0.0" max="1.0" value="0.0" step="0.05" tabindex="20">
Upvotes: 0
Views: 849
Reputation: 632
According to description of mdl slider "Although the value attribute is used to set a slider's initial value, it should not be used to modify the value programmatically; instead, use the MDL change() method. For example, assuming that slider1 is a slider object and newvalue is a variable containing the desired value, do not use slider1.value = newvalue; instead, use slider1.MaterialSlider.change(newvalue)"
https://getmdl.io/components/#sliders-section
So update your code like
$("#xyzslider")[0].MaterialSlider.change(minValue);
Updated in jsfiddle: https://jsfiddle.net/qahf2wuL/12/
Upvotes: 4