:id_element is not properly rendered with a simple solution #116

Open
konung opened this Issue Nov 14, 2011 · 9 comments

Projects

None yet

8 participants

@konung
konung commented Nov 14, 2011

This is related to other similar issues here : #69, #75, #87

None of the solutions mentioned in the tickets above worked for me:
Using it for a Rails 3.1.1 app with HTML 5 .
Just installed the gem - so I have all the latest .js files.
Using it inside a nested formtastic form.

The only way I was able to get it to work properly is by passing :input_html like so :

    = j.input :product_search, :as => :autocomplete, :url => autocomplete_product_vendor_number_products_path, :input_html => {"data-id-element" => "#exchange_order_lines_attributes_0_product_id"}

My solution works for now, but i just wanted to submit this bug report.

@marzapower
Contributor

The exact same thing happens with my Rails 3.1 application. The :id_element parameter seems to be broken when using Formtastic ...

@pilap82
pilap82 commented Feb 19, 2012

I've scratched my head for a while. I finally found out that the necessary data-id-element attribute was not generated by the helper.
so by adding

:input_html => {:id_element => '#negotiation_supplier_id'}

instead of just

:id_element => '#negotiation_supplier_id'

you solve the issue.

@lightcap
lightcap commented Mar 9, 2012

I'm seeing the same issue, though the workaround posted by@pilap82 seems not to work for me either. I assume you're suggesting that the above change is put on the autocomplete macro in the controller?

@lightcap
lightcap commented Mar 9, 2012

Oops, nevermind, that appears to be my issue :-) It goes on the helper, not the controller macro.

@dankozlowski

This isn't working for me. The element_id still isn't updating.

= f.autocomplete_field :people_to_be_tagged, autocomplete_user_first_name_posts_path, :"data-delimiter" => ', ', :placeholder => "Start typing a name to tag someone!", :input_html => {:id_element => '#user_ids'}
= text_field_tag :user_ids, ''
@mojovski

Does not work for me either:

 autocomplete_field_tag "club", '', autocomplete_club_name_clubs_path, :id_element=>"#properties_clubid", :value=>clubval 

and further

<input id="properties_clubid" name="opponent[id]" type="hidden"/>

The generated stuff is:

<input data-autocomplete="/clubs/autocomplete_club_name" data-id-element="#properties_clubid" id="club" name="oppclub" type="text" value="" />
<input id="properties_clubid" name="opponent[id]" type="hidden" />

After submitting the form, the value opponent[id] is empty.
Also after entering a value into the textfield club, using the console

$("#properties_clubid").val()

returns an empty string.

I am using the version rails3-jquery-autocomplete (1.0.9).

Does anyone have any ideas?

Thanks in advance!

@mojovski

I fixed it! :)

I had to update my js file via

rails generate autocomplete:install

Now the above code works perfectly!

@benjiec
benjiec commented Feb 6, 2013

Also, just so people know, I ran into this problem, and I found that I was blinding assigning the IDs and there were duplicates. So if you are using autocomplete for a has_many field, make sure each of the related field's input element gets a separate dom ID

@manusajith
Member

hope this issues is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment