I'm using CoffeeScript in my rails app, and I need to delay a remote ajax form submission, the main problem I'm having is debouncing the request so that the form will send once 250ms has passed without the user typing in the the form.
Right now I have something that looks like this going on, obviously it won't work so this has some debug output in it to help me out.
Taking a look at the table below, you should know that the function that I want to be "debounced" is within the element.keyup (event) ->
function, any help would be amazing!
remoteTable =
bindEvents: (element) ->
element.keyup (event) ->
console.log(event)
send: (event) ->
console.log(event)
** It would be really helpful if I could gather a few examples of how this works? ** I did see the way that underscore.js does it, but Here, this is my old method: I just can't wrap my head around how this should wok:
You can use a simple timeout for this, no need to get fancy.
I played around on coffeescript.org where they have a online "try coffeescript" translator/runner and it seems
Translates into
So
element.keyup
is actually a function invocation with a function as a parameter.Seeing this, I tried
and got:
I didn't try this with anything but I don't know of a reason why this wouldn't work. I have to confess to not doing much with coffeescript but it seems pretty straightforward.