How can I have a jQuery slider that is readonly? One that would display a value but the user wouldn't be allowed to move it?
Thanks
How can I have a jQuery slider that is readonly? One that would display a value but the user wouldn't be allowed to move it?
Thanks
The documentation says there's a .slider('disable')
function - not sure what that actually does to the slider element itself, but that may be an option for you.
.slider("disable")
works like a charm. It decreases the transparency and disables dragability. –
Furze $(".ui-slider-disabled.ui-state-disabled").removeClass("ui-state-disabled");
after you call it. –
Industrialism I tried all suggested. Only this works:
$('#mySlider').slider({ disabled: true });
Disabling it makes it transparent. If you want it to look like a normal slider, you can override slide handler to return false:
$("#mySlider").on("slide", function (event, ui) { return false; });
I have got the same issue that the slider disappears if I use directly $('#mySlider').slider( 'disable' );. I have loaded the slider fisrt..then disabled it. Though it is not a good way, but it works for me.
$('#mySlider').slider(
{
range: "min",
min: 0,
max: 100,
value: $("span", this).text(),
}
});
$('#mySlider').slider( 'disable');
You would simply have to do this:
$('#mySlider').slider( 'disable' );
$("#slider").slider("disable")
works fine, however reenabling doesn't work $("#slider").slider("enable")
I had a client request for this today. Its probably a good idea to do this as a best practice and prevent string input.
Since the slider sets the value in an <input> tag, you can make it "readonly".
<p>
<label for="amount">Price range:</label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" readonly />
</p>
<div id="slider-range"></div>
© 2022 - 2024 — McMap. All rights reserved.