Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Created October 14, 2012 03:47
Show Gist options
  • Select an option

  • Save jasonnoble/3887194 to your computer and use it in GitHub Desktop.

Select an option

Save jasonnoble/3887194 to your computer and use it in GitHub Desktop.
Problems with autocomplete
<%= simple_form_for [@user, @artist], :html => { :class => 'form-horizontal' } do |f| %>
...
<%= f.input :zipcode_id, :label => 'Zip Code', :as => :autocomplete, :url => "/zipcode/autocomplete_zipcode_zipcode" %>
...
<% end %>
http://localhost:3000/zipcode/autocomplete_zipcode_zipcode?term=900
Returns:
[{"id":"38037","label":"90001","value":"90001"},{"id":"38038","label":"90002","value":"90002"},{"id":"38039","label":"90003","value":"90003"},{"id":"38040","label":"90004","value":"90004"},{"id":"38041","label":"90005","value":"90005"},{"id":"38042","label":"90006","value":"90006"},{"id":"38043","label":"90007","value":"90007"},{"id":"38044","label":"90008","value":"90008"},{"id":"38045","label":"90009","value":"90009"},{"id":"38046","label":"90010","value":"90010"}]
Then I select 90010 from the drop down list.
This shows 90010 in the autocomplete field. I need the id field (38046) submitted with the form as zipcode_id.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment