bernii / gauge.js

100% native and cool looking JavaScript gauge
MIT License
1.42k stars 391 forks source link

.set on change not working more than once when value is scalar #150

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi all,

I am using the following function:

var setVals = [10,40];
$('form').on('change', sliderElem, function(){
                var val = $(this).val();
                setVals[0] = val;
                gauge.set(setVals);
                //gauge.set(val);
});

When I change the value in sliderElem (currently just a text field), it will run gauge.set once, but if I then change the value again, nothing happens. When I comment out gauge.set(setVals) and turn on gauge.set(val), then the change happens every time I change the value.

Maybe I can solve this differently, too. Basically what I need it to do is to display the second needle without changing it while allowing the first needle to be changeable.

Any ideas?

Thanks,

Viviana

kplindegaard commented 6 years ago

Hello there @melcher-vi. Just wanted to say I have reproduced the bug. I think, however, if you change the order or the elements and update the last element in the setVals array, the gauge will update as you expect.

var setVals = [40, 10];  // Flipped the order
$('form').on('change', sliderElem, function(){
    var val = $(this).val();
    setVals[setVals.length-1] = val; // Workaround: Update the last element
    gauge.set(setVals);
});