2014-09-25 105 views
0

我試圖在提交鏈接後清除表單,但似乎無法使其工作。提交後清除鏈接表格

鏈接/ _form.html.erb

<%= simple_form_for [question, Link.new], :remote => true, html: {id: "new_link"} do |f| %> 

鏈接/ 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(''); 
} 

控制器/ links_controller.rb

def create 
respond_to do |format| 
if @link.save 
    format.html 
    format.js 
end 
end 

回答

0

This answer似乎是一個很好的解決方案 - 添加事件處理程序的ajax:complete事件:

$("#new_link").bind("ajax:complete", function(event,xhr,status){ 
    $('#id_of_your_field').val(''); 
} 
+0

嗯,現在當我點擊提交部分未更新任何鏈接。我會用完整的js文件更新我的答案。 – Loganhinter 2014-09-25 21:11:35