[英]Dynamically generated form submit button does not work
I have a form that's part of a dynamic table. 我有一个表格是动态表的一部分。 The view is typically generated from the controller like below:
该视图通常是从控制器生成的,如下所示:
= form_for manual_coa_account, url: manual_coa_account_path(manual_coa_account), :html => {:method => 'PUT'} do |f|
%td{:style => 'width:40px'}
= f.text_field(:amount, :size => 11, :value => to_currency(f.object.amount))
%td{:style => 'width:20px'}
.control-group
%button.btn.btn-default{:type => "submit"} Update
The issue I'm having is that the Update
button does not seem to do anything when I generate a new button dynamically and append it to the table. 我遇到的问题是,当我动态生成一个新按钮并将其附加到表中时,“
Update
按钮似乎没有任何作用。 My simplified version (removed all the irrelevant and tag for readability) is below: 我的简化版本(删除了所有不相关的标签以提高可读性)如下:
tableRowHtml = "<form accept-charset='UTF-8' action='/manual_coa_accounts/" + data.id + "' class='edit_manual_coa_account' id='edit_manual_coa_account_" + data.id + "' method='post'></form>" +"<td>"+"<input id='manual_coa_account_amount' name='manual_coa_account[amount]' size='11' type='text' value="+ data.amount + ">"+"</td>"+"<td><div class='control-group'><button class='btn btn-default' type='submit'>Update</button></div>"
$(tableRowHtml).appendTo("#table tbody");
How do I generate a dynamic form that can submit? 如何生成可以提交的动态表格? Is there some rails callback that I'm missing?
我缺少一些Rails回调吗?
You can try to use event delegation here: 您可以尝试在此处使用事件委托 :
$('#table').on('click', 'input[type="submit"]', function() {
// Your code to submit form here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.