bootstrap-slider icon indicating copy to clipboard operation
bootstrap-slider copied to clipboard

Problem changing rangeHighlights attribute after initialization

Open fabiohaertel opened this issue 8 years ago • 5 comments

Hello!

Currently, it's not possible to update the 'rangeHighlights' attribute if the size of the array is different from the initial size.

If we have this:

<input id="ex1" data-slider-rangeHighlights='[{"start": 2, "end": 8}]' data-slider-id='ex1Slider' type="text" data-slider-min="0" data-slider-max="20" data-slider-step="1" data-slider-value="14"/>

And try to update the attribute like this:

var newRangedH = [{"start": 4, "end": 12}, {"start": 10, "end": 15}];
$('#ex1').bootstrapSlider('setAttribute', 'rangeHighlights', newRangedH);
$('#ex1').bootstrapSlider('refresh');

The following error happens:

Uncaught TypeError: Cannot read property 'style' of undefined

The initial size of 1 is not updated when the attribute changes. The error happens inside this condition:

if (this.rangeHighlightElements.length > 0 && Array.isArray(this.options.rangeHighlights) && this.options.rangeHighlights.length > 0) {
 }

I set up a fiddle to show the problem

http://jsfiddle.net/s9fttxdq/2/

Thanks for your attention!

fabiohaertel avatar Jan 30 '17 11:01 fabiohaertel

Thanks, I've verified that this does not work in this case.

seiyria avatar Jan 30 '17 14:01 seiyria

+1. Need a fix for this also.

dchacke avatar Feb 14 '17 18:02 dchacke

We're happy to have a PR for this if it's urgent.

seiyria avatar Feb 14 '17 18:02 seiyria

Ouch!

FYI, it's slightly different for me. I do

$(this.ref.nativeElement).bootstrapSlider('setAttribute', 'ticks', this.ticks);
$(this.ref.nativeElement).bootstrapSlider('setAttribute', 'ticks_positions', this.tickPositions);
$(this.ref.nativeElement).bootstrapSlider('refresh');

The error is thrown in line 1250 of the main js file:

this.ticks[i].style[this.stylePos] = percentage + "%";

So it looks like this.ticks[i] evaluates to undefined.

dchacke avatar Feb 14 '17 19:02 dchacke

Is there any solution for this problem.

harispp avatar Mar 21 '18 09:03 harispp