I have in my framework a trigger that sends the data of input
onchange
to a model that validates and returns, in that process has a problem, each character typed is made a submission, what I'm trying to do is the function described below (I do not want to use socket for this for now):
When there is a change in the value of the input, check if there has been another change within 0.5 seconds, if there is no trigger, if there is a further 0.5 wait to trigger check if there has been another change and so on.
So far I've come to this:
$(document).on('change keyup','input',function(e){
var $this = $(this);
e.preventDefault();
var text = $this.val();
setTimeout(function(){
var text2 = $this.val();
if(text !== text2){
//dispara o mesmo evento de novo
console.log('houve mudança de :'+ text + 'para: ' +text2);
}else{
//dispara algum função
console.log('manteve o valor de: '+text);
}
}, 500);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text'>
Apparently this is working, what I want to know is:
-
This is actually not accumulating events triggered in the same
trigger?