ion.rangeSlider icon indicating copy to clipboard operation
ion.rangeSlider copied to clipboard

Multiple slider on the same page

Open yansusanto opened this issue 5 years ago • 5 comments

Hi, I'm hoping someone may point me in the right direction as to what I'm trying to achieve here.

				var $range = $(".range-slider"),
					$from = $("#min"),
					$to = $("#max"),
					instance,
					min = 0,
					max = 1000,
					from = 0,
					to = 0;

				$range.ionRangeSlider({
					onStart: updateData,
					onChange: updateData,
					onFinish: updateData,
				});

				instance = $range.data("ionRangeSlider");

				function updateData(data) {
					from = data.from;
					to = data.to;

					$from.prop("value", from);
					$to.prop("value", to);
				}

				$from.on("change", function () {
					var val = $(this).prop("value");

					if (val < min) {
						val = min;
					} else if (val > to) {
						val = to;
					}

					instance.update({
						from: val,
					});

					$(this).prop("value", val);
				});

				$to.on("change", function () {
					var val = $(this).prop("value");

					if (val < from) {
						val = from;
					} else if (val > max) {
						val = max;
					}

					instance.update({
						to: val,
					});

					$(this).prop("value", val);
				});

Say I have another slider, do I need to create a new set of `onChange' function to target the specific slider. Just couldn't wrap my head around this.

Any pointer is much appeciated.

yansusanto avatar Jul 14 '20 13:07 yansusanto

Hi, yes you can create multiple sliders on 1 page. Just follow this demo: https://jsfiddle.net/IonDen/f1t6qpx0/

IonDen avatar Jul 15 '20 13:07 IonDen

Thanks for the response, @IonDen

Yes, I did create 2 sliders with different ids. So you're saying this is what we have to do

$range.ionRangeSlider({
      onStart: updateData,
      onChange: updateData,
      onFinish: updateData,
});

$range2.ionRangeSlider({
      onStart: updateData2,
      onChange: updateData2,
      onFinish: updateData2,
});

Is this the correct workflow?

yansusanto avatar Jul 15 '20 14:07 yansusanto

You have basic idea.

IonDen avatar Jul 15 '20 18:07 IonDen

@IonDen Thank you.

If I'm using the above js, may I know why I'm getting this console error. Am I missing something here?

Screenshot 2020-07-19 at 12 15 15 AM

Everything works fine though

yansusanto avatar Jul 18 '20 16:07 yansusanto

e.ionRangeSlider? what is e?

IonDen avatar Jul 20 '20 10:07 IonDen