I am using the Bootstrap-slider found here - https://github.com/seiyria/bootstrap-slider and currently am using v10 (although I've tried with v11 as well but the same result). This is my code:
/* For better styling - this uses Bootstrap slider */
$('.bs_sliders').each(function () {
var id = '#' + $(this).attr('id');
if (typeof window[id] !== 'undefined') {
window[id].slider('destroy');
delete window[id];
}
// .on will only work with an ID based selector not class
window[id] = $(id).slider({
formatter: function (value) {
return value;
},
}).on('change', function (ev) {
$(this).closest('li').find('.rangeUpdate').val($(this).val());
$(this).closest('li').find('.continuing_eval').removeClass('continuing_eval');
autoSave();
})
})
Basically I am trying to destroy and re-initialize a slider if it exists. Whilst it semi-works I notice that (for example) where my range is 0-100 it only goes to 10 even though the input is as follows:
<input type="text" name="54_slider" value="22" class="bs_sliders elRes" id="54_slider" data-slider-id="54_slider"
data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="22"
data-slider-handle="custom"
data-slider-rangeHighlights='[{"start":25,"end":26,"class":"grey_line"},{"start":50,"end":51,"class":"grey_line"},{"start":75,"end":76,"class":"grey_line"}]' />
<input type="text" value="22" class="rangeUpdate" data-toggle="popover" data-trigger="manual"
data-content="The permitted value range is 0-100" style="--my-content:'Undefined';" />
Additionally, it doesn't pick up on the custom elements (such as the divider lines) either. How can I make it so that when a bs-slider is reinitialized it picks up on all the custom elements and attributes??
The solution it turns out is to destroy it yourself ... What we do is clone the original element - grab its value, remove the element, reattach the clone and then set the value on the slider. Rather longwinded and you'd expect "destroy" to do it but it clearly doesn't.