Files
nairobi/app/assets/javascripts/suggest.js.coffee
Senén Rodero Rodríguez cf370cab84 Adapt suggest script for translations
Proposal, Debate, Budget Investment  and Comment will be translatable
models soon. This commit prepares suggestions script to work well with
translatable forms elements too.
2019-06-27 09:19:36 +02:00

30 lines
763 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")
if js_suggest_selector.startsWith(".")
locale = $this.closest(".translatable-fields").data("locale")
js_suggest_selector += "[data-locale=#{locale}]"
$(js_suggest_selector).html(stHtml)
timer = null
$this.on "keyup", ->
window.clearTimeout(timer)
timer = window.setTimeout(callback, 1000)
$this.on "change", callback