IonDen / ion.rangeSlider

jQuery only range slider
http://ionden.com/a/plugins/ion.rangeSlider/en.html
MIT License
2.56k stars 508 forks source link

How to trigger onChange manually #668

Closed TheEssenceSeeker closed 4 years ago

TheEssenceSeeker commented 4 years ago

I need to trigger onChange programmatically. How can I do it with jQuery or planJS? Thank you in advance!

IonDen commented 4 years ago

Hi, if you mean trigger onChange on slider, you can do it with using update method. Check this demos: http://ionden.com/a/plugins/ion.rangeSlider/demo_interactions.html

TheEssenceSeeker commented 4 years ago

Hi, if you mean trigger onChange on slider, you can do it with using update method. Check this demos: http://ionden.com/a/plugins/ion.rangeSlider/demo_interactions.html

Thank you for such a fast reply! I want to manually trigger onChange method after I use .update() to change "from" field. Is there any good way to do this?

Here is my code:

let slider = $("#payment-slider").data("ionRangeSlider");
$("#payment-sum").on("input", function () {
            console.log('value changed to ', $(this).val());
            slider.update({from: $(this).val()});
        });
IonDen commented 4 years ago

Yes: $("#payment-slider").trigger("change");

TheEssenceSeeker commented 4 years ago

Yes: $("#payment-slider").trigger("change");

I've already tried this but it doesn't work :( Probably the problem is on my side. Thank you!

IonDen commented 4 years ago

It is working even without trigger: https://jsfiddle.net/6mn4hubj/

TheEssenceSeeker commented 4 years ago

Here is an example of what I'm trying to achieve https://jsfiddle.net/dhn4kb5p/3/ When I change the value inside first input, it updates slider "from" but input2 value stays the same.

IonDen commented 4 years ago

You forgot about onUpdate callback, demo: https://jsfiddle.net/o2dzns56/

TheEssenceSeeker commented 4 years ago

I see. Thank you!