0
繼續從this(其中一個employee belongs_to role
並具有根據該角色的薪水)我想我New Employee form
更具交互性有點不同的價值觀和IDS radio_buttons:我想salary
字段的值根據從單選按鈕組中選擇的role
進行更改。simple_form f.association爲:與jQuery的操縱
我的表單現在看起來是這樣的:
<%= simple_form_for(@room) do |f| %>
<%= f.input :name, label: 'Full Name', :required => true %>
<%= f.association :role, as: :radio_buttons, :required => true %>
<%= f.input :salary, label: 'Salary', :required => true %>
<%= f.button :submit %>
<% end %>
而且我employees.js.coffee
文件中有這樣的代碼:
jQuery ->
$('#employee_employee_role_id_1').click ->
$(document.getElementById('employee_salary')).val(15)
我在那裏的值硬編碼,以確保有一個與我的表單字段沒有問題IDS。
我需要的是有.click
方法適用於所有#employee_employee_role_id_X
領域(其中X是每個單選按鈕的數量),並傳遞給.VAL()的值是role.salary
不過,作爲新手我對Rails和js/jQuery都很無語。