jquery-simple-slider icon indicating copy to clipboard operation
jquery-simple-slider copied to clipboard

Problem with dynamically added sliders

Open kviktor opened this issue 12 years ago • 5 comments

I have the scripts and css files included and on a button click I append an input to the HTML, then I call simpleSlider() on it and the slider is there, but it has no background color.

The other problem is that when I set the slider value with simpleSlider("setValue", ...) the sliders look like they are reseted and they are all set to 1.0 which seems to be the maximum value after the call.

Image

kviktor avatar Oct 22 '13 13:10 kviktor

I think i encountered the same issue with dynamically loaded Slider. I create sliders after I created html using Mustache, all sound and clear like on the homepage of slider - none of the option data attributes are used by the script. No theme, volume, steps, range, snap, etc.

Anyone knows any workaround it? I would like to use that slider but this pretty much crosses it of the table :)

pavelloz avatar Oct 28 '13 15:10 pavelloz

I'll take a look at this later tonight. I've added the show scale feature in my fork and that made me have to look at how the data-slider-* values are loaded. It's given me an idea of what is happening here.

nedwidek avatar Nov 02 '13 19:11 nedwidek

The issue is that the data-slider-* attributes are only looked at by a function that runs after the page loads. That function visits each input with data-slider="true" and creates a settings object. That settings object is then passed in to the call to SimpleSlider(settings).

The workaround is to not use input.SimpleSlider(), but rather to use:

input.SimpleSlider({ animate: false, range: '10,100' });

I've committed a change in my fork that will load the settings from the data-slider-* attributes when you do not pass in a settings object. So with my change you can use the data-slider-* attributes and then call input.SimpleSlider() and the slider will be created as you expect.

https://github.com/nedwidek/jquery-simple-slider/commits/master

Hopefully that all makes sense.

@kviktor, your second error is due to the fact that your range was not loaded. I'm pretty sure that it will go away with my change (or if you pass in a settings object).

nedwidek avatar Nov 02 '13 23:11 nedwidek

How about pulling the settings from attributes at the slider initialization when there are no settings passed? And if the settings are passed, anyway pull settings from attribute and extend it by those what are passed. That way we have default settings from attributes and additional from the function call.

Does this make sense or Im missing something crucial?

pavelloz avatar Nov 06 '13 14:11 pavelloz

Any chance that these commits in the fork gets merged in the original repo? They indeed fixed the issue for me.

diosney avatar May 28 '14 15:05 diosney