3
votes

I'm using noUiSlider and followed the tutorial how to create custom formatting:

noUiSlider.create(sliderFormat, {
start: [ 20 ],
step: 10,
range: {
    'min': [ 0 ],
    'max': [ 599 ]
},
format: {
  to: function ( value ) {
    return Math.round(value/60) + ':' + Math.round(value%60);
  },
  from: function ( value ) {
    return value;
  }
}
});

When I call

mySlider.get()

it returns a value like 1:10, which is the formatted value. I would like to get the raw value (like 70 in this example), how is that possible?

1
Do you want to get the raw value when someone is changing the slider? - Vaibhav Kumar
if you don't want to get the formatted value, then why you are formatting it, If you don't format, myslider.get will return 70. - Vaibhav Kumar
I reading the value as soon as the slider changes. I need to format it for the user experience so the slider shows a hours/minute value in the ui field. - Torsten Simon
if you want to get both the raw and formatted value, use 'update' function. You can format your value there. - Vaibhav Kumar
maybe just format it back with the reverse code of how you formatted it? - janjackson

1 Answers

3
votes

As Vaibhav Kumar suggestet, I used the update function to read the raw value:

slider.noUiSlider.on('update', function(values,handle,unencoded){
   // unencoded contains the raw value
});