Autocomplete plugin

Hi

Is it possible to use the autocomplete plugin to search using a keyword on more than one field of a model? How can I do that?

If I understand well the question the answer should be yes. If what you mean is if it is possible to use one field on a page to find data in more than one column in the table it should be possible the only thing you would need is to query the table by the columns you desire to query on.

Hi

Is it possible to use the autocomplete plugin to search using a keyword on more than one field of a model? How can I do that?

When you use autocompletion, you define a field to watch, and an endpoint to query against. Whatever query conditions you put in the method that "answers" that endpoint will be the results that appear in the autocompleter's list.

So if you had generated:

new Ajax.Autocompleter('person','/people/lookup',{});

Then in Person#lookup you would be looking for

  Person.all(:conditions => ['first_name LIKE ? OR last_name LIKE ?'],"#{params[:value]}%","#{params[:value]}%"])

Crude example, but you get the idea...

Walter

Thanks for your comments. I understand what you're saying but I guess my question had more to do with the population of the actual list, not the database query. If you use the autocomplete plugin, the list that populates under the input box has to be a certain field of a certain model. For example, when you call this helper:

model_auto_completer_result(@inventories, :inventory_id )

the inventory_id is displayed for each inventory item matching the query. I'd like to search on two fields in the inventories table and display whichever field matched in the autocomplete list.

Thanks for your comments. I understand what you're saying but I guess my question had more to do with the population of the actual list, not the database query. If you use the autocomplete plugin, the list that populates under the input box has to be a certain field of a certain model. For example, when you call this helper:

model_auto_completer_result(@inventories, :inventory_id )

the inventory_id is displayed for each inventory item matching the query. I'd like to search on two fields in the inventories table and display whichever field matched in the autocomplete list.

Back up to the line where you define @inventories. That's where you would make the filter broad enough to include hits on more than one field.

Walter