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

Option to return array index instead of array value #643

Closed lewisjenkins closed 4 years ago

lewisjenkins commented 5 years ago

When using custom values, is there a way of returning the index instead of the value?

var custom_values = [0, 10, 100, 1000, 10000, 100000, 1000000];

// be careful! FROM and TO should be index of values array
var my_from = custom_values.indexOf(10);
var my_to = custom_values.indexOf(10000);

$("#demo_5").ionRangeSlider({
    type: "double",
    grid: true,
    from: my_from,
    to: my_to,
    values: custom_values
});

In this example, instead of saving 10;10000 I would like an option to save 1;4.

In another comment you offered to add a return_value option. This would be ideal.

Thanks for your work on this plugin :)

IonDen commented 5 years ago

Hi, there is no option to save indexes to input. But if you read slider values with JavaScript, it is easy. In onChange/onFinish callbacks you will receive data object as a first argument, like this:

onFinish: function (data) {
    console.log(data.from); // index
    console.log(data.from_value); // actual value
}