I have a little JavaScript code, that loop throw in a list, and create a slider for each element. In second, it's take an event handler, so when a slider is changed, it'll write the value in to an input.
When the for run for the first time, everything is ok, the inputs gets the values, but when i change manualy the slider, it throw an error:
Uncaught TypeError: Cannot read property 'maxValue' of undefined
The code:
for (i = 0; i < sliders.length; i++)
{
noUiSlider.create(sliders[i].object[0], {
start: sliders[i].start,
step: 1,
connect: true,
range: sliders[i].range
});
sliders[i].object[0].noUiSlider.on('update', function( values, handle ) {
if ( handle ) {
console.debug(sliders[i]);
sliders[i].maxValue.val(Math.floor(values[handle]));
} else {
sliders[i].minValue.val(Math.floor(values[handle]));
}
});
}
In the sliders variable i have this:
var sliders = [
{
"object": $('#number-of-passangers'),
"start": [4, 6],
"range": {
"min": 2,
"max": 15
},
"minValue": $("#min-passanger"),
"maxValue": $("#max-passanger")
},
{
"object": $('#cost-per-day'),
"start": [3500, 65000],
"range": {
"min": 3500,
"max": 65000
},
"minValue": $("#min-cost"),
"maxValue": $("#max-cost")
},
]