我在提交链接后试图清除我的表单,但我似乎无法让它工作。
链接/ _form.html.erb
<%= simple_form_for [question, Link.new], :remote => true, html: {id: "new_link"} do |f| %>
links / create.js.erb
$('.button').append("<%= j (render :partial => 'comments/newlink', locals: {question: @question}) %>");
$('#linkpartial').html("<%= j (render :partial => 'comments/newlink', locals: {question: @question}) %>");
$('#linkform').reset("<%= j (render :partial => 'links/form', locals: {question: @question}) %>");
$("#new_link").bind("ajax:complete", function(event,xhr,status){
$('.createcomment').val('');
}
controllers / links_controller.rb
def create
respond_to do |format|
if @link.save
format.html
format.js
end
end
答案 0 :(得分:0)
This answer似乎是一个很好的解决方案 - 为ajax:complete事件添加一个事件处理程序:
$("#new_link").bind("ajax:complete", function(event,xhr,status){
$('#id_of_your_field').val('');
}