mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +02:00
make contacts searchable
This commit is contained in:
parent
b088d39b0e
commit
3d2c9c01a6
7 changed files with 56 additions and 12 deletions
|
@ -4,6 +4,7 @@
|
|||
#= require jquery.validate.additional-methods
|
||||
#= require turbolinks
|
||||
#= require bootstrap-sprockets
|
||||
#= require typeahead.bundle.min
|
||||
#= require jquery.nested_attributes
|
||||
#= require shared/jquery.validate.bootstrap
|
||||
#= require jquery-ui/datepicker
|
||||
|
@ -11,4 +12,5 @@
|
|||
|
||||
#= require shared/general
|
||||
|
||||
#= require registrar/autocomplete
|
||||
#= require registrar/application
|
||||
|
|
27
app/assets/javascripts/registrar/autocomplete.coffee
Normal file
27
app/assets/javascripts/registrar/autocomplete.coffee
Normal file
|
@ -0,0 +1,27 @@
|
|||
class @Autocomplete
|
||||
constructor: ->
|
||||
@buildAutocomplete(el) for el in document.querySelectorAll('[data-autocomplete]')
|
||||
|
||||
buildAutocomplete: (el)->
|
||||
name = el.dataset.autocomplete[1..-1].replace(/\//g, "_") # cahcing
|
||||
|
||||
$(el).typeahead 'destroy'
|
||||
$(el).typeahead(
|
||||
name: name,
|
||||
highlight: true,
|
||||
hint: false
|
||||
,
|
||||
displayKey: "display_key"
|
||||
source: (query, syncResults)->
|
||||
$.getJSON "#{el.dataset.autocomplete}?query=#{query}", (data)->
|
||||
syncResults(data)
|
||||
|
||||
|
||||
).on('typeahead:selected', (e, item) ->
|
||||
console.log e.currentTarget.id
|
||||
orig = document.querySelector('#' + e.currentTarget.id.replace(/_helper$/, ''))
|
||||
orig.value = item.value
|
||||
)
|
||||
|
||||
$(document).on "ready page:load", ->
|
||||
new Autocomplete
|
Loading…
Add table
Add a link
Reference in a new issue