1

I'm writing RoR application and I have working autocomplete. In page.coffee I have this:

jQuery ->
  $('#search').autocomplete
    source: "/autocomplete_source"

In the form I have also #select combobox in addition to the #search textbox and I'd need to pass the value of selected item as 'data' into the jQuery.autocomplete method.

In short - I need to restrict searched values by the value of combobox selected item.

How can I pass it?

Thanks

1 Answer 1

1

This should do the trick:

jQuery ->
  $('#search').autocomplete
    source: '/autocomplete_source',
    data: {}

And if you want a compltex data object, you can do this:

jQuery ->
  $('#search').autocomplete
    source: '/autocomplete_source',
    data:
      key: 'value',
      key2: 'value'
Sign up to request clarification or add additional context in comments.

4 Comments

Ok, but how can I read it? I was expecting it in the controller "autocomplete_source" in the method "index" in the params[:key], but there is any such key in the params..
Can you link to the actual library that you're using? Because according to this documentation: api.jqueryui.com/autocomplete you shouldn't see it, and there is no data option.
I'm using jQuery UI v1.10.3 and jQuery v1.11.2. So if this is not the way, how can I filter autocomplete results based by the dropdownlist selected item?
I haven't used jquery autocomplete that much. So I don't have an answer to that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.