Reputation: 57
I want to clear text_form after message submitting. This is my form:
<%= form_for :chat, :html => {:id => 'send_form'}, :url => {:controller => :chat,
:action => :chat_save }, :remote => true do |f| %>
<%= f.text_field(:text, :class => "text_field round") %>
<%= f.submit(:class => 'button round') %>
<% end %>
I`ve done, like in this topic: Clear Rails remote form after submitting. First I try this in my js file:
$('#send_form').submit(function() {
$('#chat_text').val('');
});
the text_field become clear, but it send a blank line. Then I try this one, it sends message now, but text_field doesn`t become empty:
$(document).ready(function () {
$("#send_form").live("ajax:complete", function(evt, data, status, xhr){
$('#chat_text').val('');
});
}
May be some libraries missed? Can anyone helps?
Upvotes: 0
Views: 3918
Reputation: 29599
if you're ok with waiting for a reply from the server, you can create a .js.erb
file that will be executed after the request. inferring from the form action, create a file called chat_save.js.erb
in app/views/chat
and add
$('#chat_text').val('');
Upvotes: 3