我要获取此表单名称并隐藏表单名称
<input placeholder="Nome" class="form-control" type="text"
name="morning[name]"
id="morning_name">
隐藏字段
<input placeholder="Nome" hide_label="true" required="required"
type="hidden"
name="morning[foots_attributes][0][name]"
id="morning_foots_attributes_0_name">
我的bootstrap_form
<%= bootstrap_form_with(model: @morning, url: morning_path, local: true) do |form| %>
<%= form.text_field :name, placeholder: "Nome", hide_label: true%>
<%= form.fields_for :foots do |foot| %>
<%= foot.hidden_field :name, placeholder: "Nome", hide_label: true, required: true %>
<% end %>
<%= form.submit "Registrar horário", class:"btn btn-primary", data: { disable_with:
'Registrando....' } %>
<% end %>
<%= javascript_pack_tag 'custom' %>
答案 0 :(得分:1)
您可以使用jQuery .change()
完成此操作。
$("#morning_name").change(function(){
$("#morning_foots_attributes_0_name").val(this.value);
});