Giter Club home page Giter Club logo

Comments (4)

jrunning avatar jrunning commented on June 6, 2024 4

Since WHATWG has abandoned the proposal for a multiple attribute for <input type="range">, I suspect @LeaVerou has understandably lost interest in maintaining this. However, a workaround is pretty easy.

The problem is that when you add an event listener to your <input>, it isn't automatically added to the second handle, which is rendered by a separate, generated "ghost" <input>. The solution is to manually bind your event listener to that element. I've done it like this:

function handleChange() {
  console.log('Range is %s to %s', this.valueLow, this.valueHigh);
}

const input = document.querySelector('input[type=range]');
input.addEventListener('input', handleChange);
input.nextElementSibling.addEventListener('input', handleChange.bind(input));

You can see it in action in this Stack Overflow answer. You must ensure that this code runs after multiselect loads, since it depends on input.nextElementSibling being the "ghost" input.

from multirange.

chriswheeler avatar chriswheeler commented on June 6, 2024 1

I fixed this by making the ghost change event trigger change on the original:

jQuery example but the same should be possible in pure JS:

$(document).on('change', 'input[type=range].multirange.original', function() {
	console.log(this.valueLow + ' - ' + this.valueHigh);
});
$(document).on('change', 'input[type=range].multirange.ghost', function() {
	$('input[type=range].original', $(this).parent()).trigger('change');
});

from multirange.

gnapse avatar gnapse commented on June 6, 2024

I have the same problem. Any workarounds?

from multirange.

hakassem avatar hakassem commented on June 6, 2024

Hello,
The issue is related to the clone of node. the node use the same ID.
To resolve this issue you need to update the code and and add a suffix to the second ID.
After this line:
var ghost = input.cloneNode();
Please add:
ghost.id=ghost.id+"@clone" ;// HK update to avoid Id conflict

To trigger events on both sliders:
use in the html:

first slider Id= ranger@filter@dates
second slider ID = ranger@filter@dates@clone
var processSlider = function () {
console.log('Triggered!!')
}
window.onload = function(){
document.getElementById('ranger@filter@dates').oninput=processSlider
document.getElementById('ranger@filter@dates@clone').oninput=processSlider
}

from multirange.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.