I'm trying to implement jQuery.autocomplete which I use to enter tags (much like here on SO). However, I don't want to show tags that I have already in my list. If I have added foo
already I don't want it to show up as a suggestion. The list of tags are fetched from my server. However, I have some issues with altering the ui.content
object.
I use the response method found here:
response: (event, ui)->
# Fetch already added tags
current = $('input#photo_tag_list').val().split(',')
# Filter out already added tags from result
ui.content = ui.content.filter (el) -> $.inArray(el.label, current) == -1
However, the above doesn't work. It still shows all tags. If I inspect ui.content I can see that it looks correct... Is the above async or something?!
The weird thing is that if I do:
ui.content.push({label: "Foo", value:"Bar"})
Foo
shows up in the autocomplete list. But if I do this:
ui.content = []
It still shows everything returned. I would expect an empty list.
Why would this be? How do I modify the result list correctly?
Update Got it to work based on Andrew Whitaker's solution.