jquery - Rail 4 populating select field with val of other select field -


after read lot of samples.. still have mistake in code. cant figure out whats wrong. can give me hint?

view: form 2 select fields

<%= select_tag "ops_group_id", options_from_collection_for_select(@groups, "id", "name"), :prompt => "select group"%> <%= render :partial => 'oncalls' %> 

route:

 "/projects/update_oncalls/:id" => 'projects#update_oncalls' 

controller:

def update_oncalls     @oncalls = oncall.where(:group_id => params[:id])     render :partial => "oncalls", oncalls: @oncalls   end 

partial oncalls:

<%= form.input :oncall_id, :as => :select, :collection => @oncalls, :label => false %> 

coffee:

$(document).on "change", "select#ops_group_id", ->  opsgroup = $("select#ops_group_id :selected").val()  opsgroup = "0"  if opsgroup ""  jquery.get "/projects/update_oncalls/" + opsgroup, (data) ->  $("#project_oncall_id").html (data)  return 

in log: oncall load (0.1ms) select "oncalls".* "oncalls" "oncalls"."group_id" = 1 rendered projects/_oncalls.html.erb (3.9ms)

but oncalls select ist not filled..!

your render generates new select, , jquery here $("#project_oncall_id").html (data) trying place select inside existing one.

try $("#project_oncall_id").replacewith(data) instead.

edit: double-check id of second select indeed project_oncall_id , not oncall_id.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -