0

I'm using the gem called "rails3-jquery-autocomplete" ( https://github.com/crowdint/rails3-jquery-autocomplete )

It's working fine:) But there's one thing that I want to disable.

When I type something into an input field, and there's no matching record, it always show the message that's saying "no existing match"

I want to disable this message. Is it possible?
I wish I could see inside of its source code to customize but I cannot :(

Anyone can help me about this? This might be piece of cake for someone but not for me.

For your information, I've done this command below

$ bundle exec rake assets:precompile RAILS_ENV=production

and after this it created some js files into public/assets folder

4

1 回答 1

1

Seems there is no way to pass option into the control, but I assume this might be a trick to solve your problem.

Instead of returning empty array(from backend) when no search results, try to return a array with one result has empty id and label might solve your problem, so in your rails controller, there will be something like this:

def autocomplete_action
    result = do_the_search 
    if result.count == 0
      result = [{ id: "", label: "" }] # !! do the trick here
    end

    respond_with result # assume you have "respond_to :json" in your controller
end

Here is why I am doing this:

The reason why I think this might work is because if no result return, the autocomplete control will build a fake record with id equals to empty represent no result.

 if(arguments[0].length == 0) {
    arguments[0] = []
    arguments[0][0] = { id: "", label: "no existing match" } // hacked here
 }

But I do think this definitely not the right way to solve this problem, but for now it's workaround to solve your problem quickly.

Hope it helps, thanks.

于 2013-07-15T07:12:32.217 回答