我想在我的表单中使用dependents字段,但我的输入不是hidde 我按照本教程https://www.driftingruby.com/episodes/dependent-form-fields
进行了操作我的application.js
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require now-ui-kit
//= require bootstrap-datepicker
//= require bootstrap-switch
//= require moment.min
//= require nouislider.min
//= require jquery.bootstrap.wizard
//= require jquery.validate.min
//= require paper-bootstrap-wizard
//= require underscore
//= require dependent-fields
//= require_tree .
$(document).ready(function() {
DependentFields.bind()
});
我的观点
<%= simple_form_for @contrat do |f| %>
<%= f.error_notification %>
<%= f.input :num_mandat, label: 'Numero Mandat' %>
<%= f.input :mandat_type, label: 'Type Mandat' %>
<%= f.input :client_type, label: 'Type de personne', collection: ['Physique', 'Morale'], id: 'client_choice' %>
<%= content_tag :div, class: 'js-dependent-fields', data: { 'data-select': 'client_choice', 'data-option-value': 'Physique'} do %>
<%= f.input :sexe_phi, collection: ['Mme', 'Mr'] %>
<% end %>
<%= f.button :submit, "Valider" %>
答案 0 :(得分:0)
尝试更改下面的表单。
<%= simple_form_for @contrat do |f| %>
<%= f.error_notification %>
<%= f.input :num_mandat, label: 'Numero Mandat' %>
<%= f.input :mandat_type, label: 'Type Mandat' %>
<%= f.input :client_type, label: 'Type de personne', collection: ['Physique', 'Morale'], id: 'client_choice' %>
<%= content_tag :div, class: 'js-dependent-fields', data: { 'select-id': 'client_choice', 'option-value': 'Physique'} do %>
<%= f.input :sexe_phi, collection: ['Mme', 'Mr'] %>
<% end %>
<%= f.button :submit, "Valider" %>
<% end %>
您尚未正确实施content_tag。
<%= content_tag :div, class: 'js-dependent-fields', data: { 'select-id': 'client_choice', 'option-value': 'Physique'} do %>
<%= f.input :sexe_phi, collection: ['Mme', 'Mr'] %>
<% end %>
请查看here以获取更多信息。