In HTML5, INPUT type='number' user can change the value by clicking the up / down arrows in the INPUT field. The user can also click in the field for focus or to edit its contents.
Is there any easy way to distinguish these two actions from a click trigger?
from @cvsguimaraes is the answer that better demonstrates the theory.
using my methodology, here is my finished (?) version. goal: make sure that using regular +/- triggers change triggers.
// input/mouseup triggers to call change from +/- mouse clicks // want to wait 500ms before calling change in case successive clicks render.inputCh = false; render.inputCt = 0; render.inputFn = function(e) { render.inputCh = true; } render.mouseupFn = function(e) { if( render.inputCh ) { render.inputCh = false; render.inputCt++; setTimeout( next, 500 ); } function next() { render.inputCt--; if( render.inputCt ) return; var change = document.createEvent("Event"); change.initEvent('change',true,true); e.target.dispatchEvent(change); } } // using input/mouseup triggers document.getElementById('number').addListener('input',render.inputFn,true); document.getElementById('number').addListener('mouseup',render.mouseuptFn,true); // normal change trigger - will be called normally and via +/- mouse click document.getElementById('number').addListener('change',changeFn,false);
it still works flawlessly on chrome, except that when you remove focus from an ITEM, the change trigger turns on again. I solved this with a low-change trigger that stops propagation if the previous change call was from mouseup .
cc young
source share