我想点击删除时将is_deleted
设置为true。我部分完成它但是当我点击删除它时,只需将所有嵌套部门设置为is_deleted
即可。
这是我的父母表格:
.h3 Process Step
= f.fields_for :departments do |d|
%div.fields
= render 'department_fields', :f => d
%div.fields
= link_to_add_fields "Add Department", f, :departments
Here is my nested_form
%div.fields#department_fields
= f.input :title
= f.text_field :is_deleted, id: "is_deleted", class: "is_deleted"
.remove_department remove
这是我的javascript:
:javascript
$(document).on('click', '.remove_department', function () {
$('.is_deleted').val('1');
})
这是我生成的html:
<div class="col-sm-2 col-md-offset-1" style="outline: 1px solid black;">
<div class="h3">Process Step</div>
<div class="fields">
<div class="fields" id="department_fields">
<div class="form-group string required dealership_departments_title"><label class="string required control-label" for="dealership_departments_attributes_0_title"><abbr title="required">*</abbr> Title</label><input class="string required form-control" id="dealership_departments_attributes_0_title" name="dealership[departments_attributes][0][title]" type="text" value="test"></div>
<input class="is_deleted" id="is_deleted" name="dealership[departments_attributes][0][is_deleted]" type="text" value="1">
<div class="remove_department">remove</div>
</div>
<script>
$(document).on('click', '.remove_department', function () {
//e.stopPropagation();
//alert($('.is_deleted').val());
$('.is_deleted').val('1');
//$(this).parent().hide();
})
</script>
</div>
<input id="dealership_departments_attributes_0_id" name="dealership[departments_attributes][0][id]" type="hidden" value="7"><div class="fields">
<div class="fields" id="department_fields">
<div class="form-group string required dealership_departments_title"><label class="string required control-label" for="dealership_departments_attributes_1_title"><abbr title="required">*</abbr> Title</label><input class="string required form-control" id="dealership_departments_attributes_1_title" name="dealership[departments_attributes][1][title]" type="text" value="Check In"></div>
<input class="is_deleted" id="is_deleted" name="dealership[departments_attributes][1][is_deleted]" type="text">
<div class="remove_department">remove</div>
</div>
<script>
$(document).on('click', '.remove_department', function () {
//e.stopPropagation();
//alert($('.is_deleted').val());
$('.is_deleted').val('1');
//$(this).parent().hide();
})
</script>
</div>
我想要的是在点击&#34时将is_deleted的设定值设为true;删除&#34;与该字段相关
答案 0 :(得分:2)
这:
:javascript
$(document).on('click', '.remove_department', function () {
// change this - > $('.is_deleted').val('1'); to ->
$(this).siblings('.is_deleted').val('1');
})
答案 1 :(得分:0)
我刚刚解决了我自己。
$('.remove_department').on('click', function(event) {
$(this).prev().val('1');
})