Function Debouncing with Underscore.js
Double submission in a form is the worst thing that can happen to you. Fortunately with the
_.debounce()
method it's easy to prevent it. What you have to do is set the third parameter of the debounce()
method to true. This way, the function is triggered when you click the submit button but it won't be triggered again in case the submit button is clicked the second time in quick succession (double submission).// prevent double click
$('button.my-button').on('click', _.debounce(function() {
console.log('clicked')
// code to handle form submition
}, 500, true)
No comments:
Post a Comment