0
I have in my framework a trigger that sends the data from input
onchange
for a model that validates and returns, in this process there is a problem, each character typed is made a submission, what I’m trying to do is the function described below (I don’t want to use socket for this while):
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 to wait another 0.5 to fire check if there has been another change and so on.
So far I’ve come to that:
$(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 not actually accumulating events shot into it
Trigger ?