crowdint / rails3-jquery-autocomplete

An easy and unobtrusive way to use jQuery's autocomplete with Rails 3

Home Page:http://rubygems.org/gems/rails3-jquery-autocomplete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extra Conditions

timscott opened this issue · comments

How can I add extra conditions?

For example, I'm using the autocomplete to add some child things to a parent thing. I don't want to return things that have already been added because it's not valid to add them twice. I would like place a JS hook that lets me pass an array to the server of the IDs of already added things and then exclude them from the result.

This is a very common use case. I'm pretty sure that the jquery ui supports it, so it would be a matter of exposing it.

Thanks for this great plugin!

@timscott is it that you need autocomplete to return unique results ? if so you you could use a scope which returns only distinct items.

@manusajith No, it's not that I need unique results. Let me try to explain with an example.

Imagine a page where the user chooses which of his friends put into his "special friends" group. Users have lots of friends, so we need autocomplete. The user has just added Sam and Emily to this group, but he has not yet pressed Save. Now he types in the autocomplete to select more friends to add. It would be wrong for our autocomplete results to include Sam and Emily because it is nonsensical to add them twice to the same group.

I have solved this problem before with other autocomplete libraries by passing an array of "ids_to_exclude" as parameter.

To put it more abstractly, we might have transient state on the page that can affect what we want to autocomplete to return, and the way to handle that is to allow passing parameters.