-
Beta Was this translation helpful? Give feedback.
Answered by
tossik8
Jul 21, 2025
Replies: 1 comment
-
|
I solved it as follows: import noUiSlider from "nouislider";
/**
*
* @param {number[]} values
* @param {number} step
* @param {string} event
* @returns
*/
export default (values, step, event) => ({
init() {
this.slider = noUiSlider.create(this.$el, {
connect: true,
range: {
min: values[0],
max: values[1]
},
format: {
to: function (value) {
return parseInt(value);
},
from: function (value) {
return parseInt(value);
}
},
step: step,
start: [values[0], values[1]]
});
const min = values[0];
const max = values[1];
this.slider.on("slide", (values) => {
window.dispatchEvent(
new CustomEvent(event, {
detail: {
trigger: this.$el.id,
min: values[0] === min ? "" : values[0],
max: values[1] === max ? "" : values[1]
}
})
);
});
if (this.$el.children.length > 1) {
this.$el.children[0].remove()
}
},
setHandles(newValues) {
if (newValues.trigger !== this.$el.id) {
this.slider.set(
[newValues.min || values[0], newValues.max || values[1]],
false,
false
);
}
}
});I manually remove the previous slider in the initializer. I have to do it this way because, while the destroy hook works and correctly removes the element, when popstate event happens, the browser restores all the DOM elements that were present on the page without the effects of the destroy hook. In other words, the previous slider is still present there despite the destroy. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tossik8
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved it as follows: