Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:04:29+00:00 2026-06-12T13:04:29+00:00

I have 2 different autocomplete fields on a page each to be populated from

  • 0

I have 2 different autocomplete fields on a page each to be populated from different sources in the database. My problem is when I test the page, the two autocomplete behaviors sometimes get switched in each others text fields.

My view partials looks like the following (I followed a railscasts):

<fieldset>
  <%= f.text_field :ability_title, {:class => 'autocomplete_field', data: { autocomplete_source: abilities_path } } %>
  <%= f.label :points %>: <%= f.text_field :points %>
  <%= f.hidden_field :_destroy %>
  <%= link_to "remove", '#', class: "remove_fields" %>
</fieldset>

<fieldset>
  <%= f.text_field :mission_title, {:class => 'autocomplete_field', data: {autocomplete_source: missions_path } } %>
  <%= f.hidden_field :_destroy %>
  <%= link_to "remove", '#', class: "remove_fields" %>
</fieldset>

My javascript:

jQuery ->
  $('fieldset').live 'click', ->
    $('.autocomplete_field').autocomplete
      source: $('.autocomplete_field').data('autocomplete-source')

And My controllers:

def index
  if params[:term].present?
    @abilities = Ability.search_titles(params[:term])
  else
    @abilities = Ability.all
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @abilities }
  end
end

def index
  if params[:term].present?
    @missions = Mission.search_titles(params[:term])
  else
    @missions = Mission.all
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @missions.map(&:title) }
  end
end

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:04:31+00:00Added an answer on June 12, 2026 at 1:04 pm

    I think you just need to differentiate both text fields by ids, eg:

    <fieldset>
      <%= f.text_field :ability_title, {:id => 'autocomplete_field1', data: { autocomplete_source: abilities_path } } %>
      <%= f.label :points %>: <%= f.text_field :points %>
      <%= f.hidden_field :_destroy %>
      <%= link_to "remove", '#', class: "remove_fields" %>
    </fieldset>
    
    <fieldset>
      <%= f.text_field :mission_title, {:id => 'autocomplete_field2', data: {autocomplete_source: missions_path } } %>
      <%= f.hidden_field :_destroy %>
      <%= link_to "remove", '#', class: "remove_fields" %>
    </fieldset>
    My javascript:
    
    jQuery ->
      $('fieldset').live 'click', ->
    
        $('#autocomplete_field1').autocomplete
          source: $('#autocomplete_field1').data('autocomplete-source')
        $('#autocomplete_field2').autocomplete
          source: $('#autocomplete_field2').data('autocomplete-source')
    

    EDIT:
    more elegant solution:

    jQuery ->
      $('fieldset').live 'click', ->
        $('#autocomplete_field1, #autocomplete_field2').each (index, element) =>
          $(element).autocomplete
            source: $(element).data('autocomplete-source')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have different php output in jQuery-based tabs. This output is formed from database
I have successfully implemented Autocomplete field from database using sfWidgetFormJQueryAutocompleter but i cannot a
I have different blocks of 34 threads each (0...33). I need to find a
I have different projects written in .NET 3.5 and some unit test projects to
I now have a working JavaScript autocomplete function, thanks to help from many of
Basically, I have correctly followed different tutorials. Now, my models are taken from a
I have a JSF page where users can enter their car into my database.
Here is the problem. I have multiple tag forms in my page. They are
I have Autocomplete attached to different types of input box. It loads items whenever
I have two autocomplete scripts, one of them makes use of (A) php/mysql/html/jquery and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.