gvas / knockout-jqueryui

Knockout bindings for the jQuery UI widgets.
http://gvas.github.com/knockout-jqueryui/
MIT License
103 stars 38 forks source link

Slider bug #4

Closed elbrus closed 11 years ago

elbrus commented 11 years ago

Hi,

I've checked slider sample: http://gvas.github.io/knockout-jqueryui/slider.html

It seems, that write function isn't working (it's not called at all). So you can change values in input fields, and that will affect slider. But if you'll try to slide, then input fields will stay the same.

Btw, really useful project ;)

Regards, elbrus

gvas commented 11 years ago

The slider binding (and jQuery UI's slider widget) has separate 'value' and 'values' options. Only 'value' is bound two way. If you need multiple handles on your slider then use the 'widget' option and the 'change' event:

single handle: http://jsfiddle.net/7XCmL/1/ multiple handles: http://jsfiddle.net/jZCay/6/

Regards, G

elbrus commented 11 years ago

Great, thanks!

julienaubert commented 10 years ago

Another option is to use the "event" binding available, e.g. below the jqueryui "slide" event is used:

                <div id="price-slider-id" data-bind="slider: {
                    range: true,
                    min: 0,
                    max: max_possible_price,
                    values: price_values,
                    slide: price_slide
                 }">
                </div>

    self.min_price = ko.observable(0);
    self.max_price = ko.observable(9999);
    self.max_possible_price = ko.observable(9999);
    self.price_values = ko.computed(function() {
        return [self.min_price(), self.max_price()];
    });
    self.price_slide = function(event, ui) {
        self.min_price(ui.values[0]);
        self.max_price(ui.values[1]);
    }
gvas commented 10 years ago

Indeed, that's the simplest solution, thanks!

The jsfiddle using this technique: http://jsfiddle.net/gvas/jZCay/7/

gvas commented 10 years ago

35 has made the "values" option bidirectional, it's no longer required to handle the slide event explicitly.