Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oninput and onchange do not work on second handle #19

Open
kmrastegar opened this issue Nov 17, 2016 · 4 comments
Open

oninput and onchange do not work on second handle #19

kmrastegar opened this issue Nov 17, 2016 · 4 comments

Comments

@kmrastegar
Copy link

Is there a way around this? the events only fire when I move the first handle

@gnapse
Copy link

gnapse commented Nov 18, 2016

I have the same problem. Any workarounds?

@jrunning
Copy link

jrunning commented Feb 7, 2017

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.

@hakassem
Copy link

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
}

@chriswheeler
Copy link

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');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants