scoped_search icon indicating copy to clipboard operation
scoped_search copied to clipboard

Use function for complete value

Open johnpmitsch opened this issue 9 years ago • 4 comments

It would be nice to pass a function that returns a hash to complete value to be used for autocomplete

for instance

scoped_search :on => :xyz, :complete_value => :create_hash

def create_hash
  ....
  my_new_hash
end

johnpmitsch avatar Jun 04 '15 18:06 johnpmitsch

Can you describe your use case for this?

wvanbergen avatar Jun 10 '15 10:06 wvanbergen

sure, so I am doing this on a two-column version number, one is major and the other minor. so version 3.1 is stored in as major => 3 and minor => 1. This proved difficult to add autocomplete as I am using scoped search on the major column with a custom query. The autocomplete currently will return major versions only. So I would write a custom function to make a hash of all of the major and minor versions as a float and use that in complete value.

I realize this seems like a particular case, but I can imagine other situations that this would be useful, and increases the flexibility of the gem's functionality, especially while using custom search queries.

johnpmitsch avatar Jun 12 '15 12:06 johnpmitsch

while inefficient, many times I've found myself adding another db column in favour of search usability, maybe you could simply have a label attribute that you can search on.

ohadlevy avatar Oct 23 '15 19:10 ohadlevy

@ohadlevy this is a good idea, thanks :)

johnpmitsch avatar Oct 23 '15 19:10 johnpmitsch