item.querySelector("input[body*='_destroy']").value = 1
<%= simple_form_for ([@survey]) do |f| %> <%= f.input :name, label:"Survey name"%> <div data-controller='nested', data-nested-index-value='QUESTION_RECORD'> <template data-nested-target="template"> <%= f.simple_fields_for :questions, Question.new, child_index: 'QUESTION_RECORD' do |question| %> <%= render "question_fields", f: question %> <% end %> </template> <%= f.simple_fields_for :questions do |question| %> <%= render "question_fields", f: question %> <% end %> <!-- Inserted elements will be injected before that target. --> <div data-nested-target="add_item"> <%= f.button :submit, "Add question", data: {action:"nested#add_association"} %> </div> </div> <%= f.submit 'Create survey' %> <% end %>
<div class="nested-wrapper" data-new-record="<%= f.object.new_record? %>" data-controller='dynamic-select'> <%= f.input :category do %> <% f.select :category, Question.category_select, selected: f.object.category, 'data-dynamic-select-target': 'select', 'data-action': 'dynamic-select#selected' %> <% end %> <%= f.input :body, label:"Question" %> <%= f.button :submit, "Delete question", data: {action:"nested#remove_association"} %> <%= f.hidden_field :_destroy %> <div data-controller='nested', data-nested-index-value='ANSWER_RECORD' data-dynamic-select-target='choice'> <template data-nested-target="template"> <%= f.simple_fields_for :answers, Answer.new, child_index: 'ANSWER_RECORD' do |answer| %> <%= render "answer_fields", f: answer %> <% end %> </template> <%= f.simple_fields_for :answers do |answer| %> <%= render "answer_fields", f: answer %> <% end %> <div data-nested-target="add_item"> <%= f.button :submit, "Add answer", data: {action:"nested#add_association"} %> </div> </div> <div data-controller="nested-form" data-dynamic-select-target='long'> </div> </div>
<div class="nested-wrapper" data-new-record="<%= f.object.new_record? %>"> <%= f.hidden_field :id %> <%= f.input :body, label:"Answer" %> <%= f.button :submit, "Delete answer", data: {action:"nested#remove_association"} %> <%= f.hidden_field :_destroy %> </div>