Files
nairobi/app/assets/javascripts/suggest.js.coffee
Javier Martín e655c3c958 Fix suggestions keyup timeout.
The browser was generating one AJAX request per keystroke, ignoring the
timeout. The clearTimeout() function needs to be called with the ID
value returned by setTimeout().
2018-06-28 21:06:32 +02:00

26 lines
565 B
CoffeeScript

App.Suggest =
initialize: ->
$('[data-js-suggest-result]').each ->
$this = $(this)
callback = ->
$.ajax
url: $this.data('js-url')
data: {search: $this.val()},
type: 'GET',
dataType: 'html'
success: (stHtml) ->
js_suggest_selector = $this.data('js-suggest')
$(js_suggest_selector).html(stHtml)
timer = null
$this.on 'keyup', ->
window.clearTimeout(timer)
timer = window.setTimeout(callback, 1000)
$this.on 'change', callback