Topic: jquery ui autocomplete with labels and values
I have a view with a field which uses Jquery UI autocomplete (http://jqueryui.com/demos/autocomplete/) to populate the field selecting from a javascript array (following Railscast http://railscasts.com/episodes/102-auto -revised).
<div class="field">
<%= f.text_field :person_fullname, data: {autocomplete_source: Person.order(:firstname).map(&:fullname)}%>
</div>This creates a data array in the format:
[ "Choice1", "Choice2" ]
I would like to use the autocomplete above to actually select a value (the Person.id), so need to form a data array in the format:
[ { label: "Choice1", value: "value1" }, ... ]
I'd be grateful for any advice on how I can create this array.
Thanks in advance.
Last edited by d_a_n (2012-02-23 19:36:41)