crowdint / rails3-jquery-autocomplete

An easy and unobtrusive way to use jQuery's autocomplete with Rails 3
http://rubygems.org/gems/rails3-jquery-autocomplete
MIT License
917 stars 367 forks source link

auto complete on name / save the id #242

Closed mhmoudgmal closed 10 years ago

mhmoudgmal commented 10 years ago

Hi there, i'm following nested models/ nested forms tutorial for adding dynamically the fields_for some nested objects

i have an issu here when in one of the nested forms i have auto-complete-field which autocomplete on -name- but i have to save the -id- not the name,

so i provided the id_element: "#user_id" to refer to the id of the hidden field which hold the user_id

<%= f.autocomplete_field :user_id, autocomplete_user_name_orders_path, id_element: "#user_id", class: "form-control", placeholder: "foo bar" %>

<%= f.hidden_field :user_id, id="user_id" %>

but the problem here, when adding new nested form, using the link_to_add_fields it renders the nested form below the previous one, but the params when the form is submitted sends the user_id only for one of the many nested forms that have been added

"check"=>{"name"=>"Check1", "orders_attributes"=>{"1384356270355"=>{"user_id"=>"6", "_destroy"=>"false"}, "1384356273476"=>{"user_id"=>"", "_destroy"=>"false"}}}

all because, the id of the hidden field is not unique for every newly added nested form

i need your help to overcome this issue Thanks in advance

KindRegards, Mhmoud

manusajith commented 10 years ago

@MhmoudGmal you should specify a unique id for your hidden field, else it will update only the first element with user_id. This is not a bug/issue with this gem

mhmoudgmal commented 10 years ago

thanks, i already overcome this situatio, thanks

On Fri, Nov 22, 2013 at 11:36 AM, Manu S Ajith (Neo) < notifications@github.com> wrote:

@MhmoudGmal https://github.com/MhmoudGmal you should specify a unique id for your hidden field, else it will update only the first element with user_id. This is not a bug/issue with this gem

— Reply to this email directly or view it on GitHubhttps://github.com/crowdint/rails3-jquery-autocomplete/issues/242#issuecomment-29060103 .