0

I have an autocomplete field on my productline table, where i type the a food name and find it. However, i dont want to save this value, instead: i want to save the food_id!

see my autocomplete field on my view:

<%= f.autocomplete_field :prl_desc, autocomplete_calorie_cal_desc_productlines_path, class: 'linestringinput', placeholder: "Parent Food" %>

Thanks in Advance!

Son Kurc
  • 5
  • 6
  • Possible duplicate of https://stackoverflow.com/questions/13443012/rails-how-do-i-autocomplete-search-for-name-but-save-id . I don't believe it's supported out of the box, you'll need to have the controller return a label + id then add some JS to capture the id into a hidden field. – TomDunning Dec 31 '18 at 14:41

1 Answers1

1

Here are the details of setting id of the selected object.

If you need to use the id of the selected object, you can use the id_element attribute too:

f.autocomplete_field :brand_name, autocomplete_brand_name_products_path, :id_element => '#some_element'

This will update the field with id *#some_element with the id of the selected object. The value for this option can be any jQuery selector.

wasipeer
  • 1,015
  • 11
  • 23
  • dear wasipeer, thank you for the right direction, but in the documentation i did not find anything about how to define #some_element. Can you please explain this further? Thank you! – Son Kurc Jan 02 '19 at 08:16