JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css">
<script src="http://seiyria.github.io/bootstrap-slider/javascripts/bootstrap-slider.js"></script>
<link rel="stylesheet" href="http://seiyria.github.io/bootstrap-slider/stylesheets/slider.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>
<br/><br/>
<input type="text" class="slider form-control" value="" data-bind="sliderValue:{value: selectedV, min:0, max: 22, step: 2, tooltip: 'always'}"/>
<p>Selected value: <b data-bind="text: selectedV">A</b></p>
JavaScript
ko.bindingHandlers.sliderValue = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var params = valueAccessor();
// Check whether the value observable is either placed directly or in the paramaters object.
if (!(ko.isObservable(params) || params['value']))
throw "You need to define an observable value for the sliderValue. Either pass the observable directly or as the 'value' field in the parameters.";
// Identify the value and initialize the slider
var valueObservable;
if (ko.isObservable(params)) {
valueObservable = params;
$(element).slider({value: ko.unwrap(params)});
}
else {
valueObservable = params['value'];
// Replace the 'value' field in the options object with the actual value
params['value'] = ko.unwrap(valueObservable);
$(element).slider(params);
}
// Make sure we update the observable when changing the slider value
$(element).on('slide', function (ev) {
valueObservable(ev.value);
});
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var modelValue = valueAccessor();
var valueObservable;
if (ko.isObservable(modelValue))
valueObservable = modelValue;
else
valueObservable = modelValue['value'];
$(element).slider('setValue', valueObservable());
}
};
function ticketViewModel() {
var self = this;
self.selectedV = ko.observable(2);
}
ko.applyBindings(ticketViewModel());