in my rails application im loading a compose mail form by sending ajax request
the code of my compose.js file is
$(‘#main’).html(“<%= j render :partial =>”smails/form” %>”);
now in my compose form i have implemented an autocomplete field using jquery autocomplete plugin which is working fine when im loading the form without ajax. i think this is because im using document.ready, but i dont know how to use anything else.
code for my autocomlete.js.coffee file
$(document).ready ->
split = (val) ->
val.split /,\s*/
extractLast = (term) ->
split(term).pop()
$('#smail_receiver').autocomplete
source: "/autocomplete/users"
search: ->
term = extractLast(@value)
false if term.length < 2
focus: ->
false
select: (event,ui) ->
terms = split(@value)
terms.pop()
terms.push ui.item.value
terms.push ""
@value = terms.join(",")
false
i also tried document.on
There is probably a better way by using the “on” binding but you could just call your:
in the success method of the ajax call that creates the form. You could also put it in your compose.js file after the form is rendered.
As said above there is probably a tidier solution but this would do the trick.