0

I am trying to clear my form after I submit a link but I can't seem to get it to work.

links/_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
Loganhinter
  • 67
  • 10

1 Answers1

0

This answer seems like a good solution - Adds an event handler for the ajax:complete event:

$("#new_link").bind("ajax:complete", function(event,xhr,status){
  $('#id_of_your_field').val('');
}
Community
  • 1
  • 1
Tom Kadwill
  • 1,448
  • 3
  • 15
  • 21
  • Hmm, now when I click submit the links partial isn't updated either. I'll update my answer with the full js file. – Loganhinter Sep 25 '14 at 21:11