我正在尝试显示确认按钮,然后再在轨道上发送红宝石表单。
问题是使用其解决方案Im无效。首先,它两次显示警报,然后按两次按钮,则不发送表单,并且什么也没有发生。
这是我的代码
<%=form_for @transaction, :url => delete_duplicated_items_transactions_path(),:html=>{:class=>"form-horizontal bol-form"} do |f|%>
<div>
<script type="text/javascript">
var checked = false;
function selectAll(){
checked = !checked;
console.log(checked);
$("input:checkbox").each(function(){
$(this).attr('checked', checked);
});
return false;
}
</script>
<table class="admin-table data-table" id="usertable">
<thead>
<tr>
<th><input type="checkbox" onclick="selectAll()">Select All</a></th>
<th>Bill of Lading Name</th>
<th>Product Lot id</th>
</tr>
</thead>
<tbody id="bill_of_ladings_body">
<% duplicated.each do |element|%>
<tr id="row_user_<%=element["product_lot"].id%>">
<td><%= check_box_tag "product_lots[]", "#{element["bill_of_lading"].id.to_s};#{element["product_lot"].id.to_s}" %></td>
<td><%=link_to element["bill_of_lading"].name,edit_bill_of_lading_path(:id => element["bill_of_lading"].id)%></td>
<td><%= element["product_lot"].id %></td>
</tr>
<%end%>
</tbody>
</table>
</div>
<div class="admin-table data-table">
<br>
<td align="right">
<%=f.button "Remove from Bill of Ladings", name: "transaction_type",value: 'remove', :class=>"btn btn-info","data-loading-text"=>"Processing..."%>
<%=f.button "Remove from Bill of Ladings and Recycle", name: "transaction_type", value: 'remove_and_recycle', data:{confirm:'If you proceed, the system will delete the selected Lot IDs from the selected Bill Of Ladings and will then recyle all Lot IDs added on the previous step. Any Lot ID that is not selected on this list will not be removed from the corresponding Bill of Lading/s and will not be recycled. Are you sure you want to continue?'}, :class=>"btn btn-danger" %>
</div>
<% end %>
我在这里做错了什么?
答案 0 :(得分:2)
首先,您谈论警报和确认这是两件事。而且,您还有一个具有Alert类的div,更具体些。
第二,Rails的ujs“确认”选项的正确语法为data: {confirm: 'somestring'}}
,您缺少“数据:”键。
https://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#confirmations
此外,在该链接的“确认”部分下面,您有一个“自动禁用”部分,因为您正在使用data-loading-text
,并且Rails已经可以使用data-disable-with
来处理