jquery - Dynamic forms - Auto fill fields based on previous auto complete -


i have form 2 fields phone , name want when user selects phone number using ajax autocomplete name field auto filled name correspond phone number.

watching railscasts episode able make ajax autocomplete works, clean way of doing auto filling?

patients_controller

class patientscontroller < applicationcontroller   def index    @patients = patient.order(:phone).where('phone ?', "%#{params[:term]}%")    json_data = @patients.map(&:phone)    render json: json_data   end end 

reservations.coffee

$(document).ready ->   $('#patient_phone').autocomplete   source: "/patients/index" 

_form.erb

<%= f.fields_for :patient, appointment.patient |patient| %>   <%= patient.text_field :phone, id: 'patient_phone' %>   <%= patient.text_field :name %>   <%= f.submit %> <% end %> 

not sure how build relationship between name , phone number can auto fill name inside autocomplete select event this

$(document).ready ->   $('#patient_phone').autocomplete     source: "/patients/index"     select: (event, ui) ->       selected_phone_number = $(event.target).val()       // fill in value name field here 

see: http://api.jqueryui.com/autocomplete/#event-select


Comments

Popular posts from this blog

Multilayer CSV to filtered excel -

Listboxes in c# -

ios - Why must I define variables twice in the Header file? -