0
在我的Rails應用程序我有兩個「button_to」標籤(所以他們的形式)如何輸入複選框附加到形式(button_to)
= button_to("Validate", validate_contracts_path , {method: :patch, class: "bulk-selection"})
= button_to("Sign", sign_contracts_path , {method: :patch, class: "bulk-selection"})
和我在一個表中有如下一個複選框集,每個複選框代表一行,他們將執行批量操作,並且複選框不包含在表單中。
td = check_box_tag "selected_records[#{record.id}]"
我想知道是否有可能附加複選框,當其中一個按鈕被點擊。
的多個軌道的方式更好,但它會是巨大的,如果它與JS
實現感謝
碼詳情: 我不知道還有什麼可以添加到Rails代碼。在這裏,你是在HTML:
按鈕
<form class="button_to" method="post" action="/contracts/sign">
<input type="hidden" name="_method" value="patch">
<input class="bulk-selection" type="submit" value="Firm">
<input type="hidden" name="authenticity_token" value="rTxalZoJ7H4VgSsa4dlrpCe+/uXitZDRhFo6F/qIZbgIoHTh42Qb2gy9dvgDmtKqT2L1x0oYx6EzPXBNKB0KBA==">
</form>
細胞的表
<td><input type="checkbox" name="selected_records[1]" id="selected_records_1" value="1"></td>
<td><input type="checkbox" name="selected_records[2]" id="selected_records_2" value="2"></td>
...
<td><input type="checkbox" name="selected_records[10]" id="selected_records_10" value="10"></td>
您是否需要提供更多的代碼細節? – hgsongra
完成!告訴我如果你需要別的東西!感謝您的時間 – Quin
因此,複選框不在表單中,您需要在jQuery中獲取所有選中的複選框並將其附加到表單中。 'chekedvalues =「」; ()函數(){(input [name =「test」]:checked')。each(function(){//然後獲取表單對象並添加新的字段形成這個'chekedvalues' – hgsongra