Clearing TEXTAREA After AJAX Submit


This is one of those simple questions that is hard to search and find an answer for, probably because most people just 'get it'.

Well, I have what I hope is a simple one.

I have the following:

<% form_remote_for(:chat_message, :url => chat_messages_path(@chat), :update => 'message') do |f| %> <%= f.text_area :message %> <%= submit_tag "Send" %> <% end %>

Works all fine and dandy but when I submit, the data is sent but I would like the text area to be blanked out again. It contains the submitted text.

What am I doing wrong?

Thanks, H


Add an html id to your form_remote_for() and then in your RJS file: 'Form.reset', 'your_form'

Hope this helps.

Hunter Hillegas wrote:

<% form_remote_for(:chat_message, :url => chat_messages_path (@chat), :update => 'message') do |f| %> <%= f.text_area :message %> <%= submit_tag "Send" %> <% end %>

Contradicting Zack's answer, here's a snip from my post "How to chat":

  form_remote_for( :chat,          :url=>{ :action=>:utter },         :html=>{ :id => 'chat_panel_'+panel_id.to_s,                  :style => 'display:inline' },       :update=>'panel_'+panel_id.to_s+'_new_content_script',      :loading=>load,     :complete=>comp,        :after=>"chat_utterance.value='';"     ) do |f|

Note the line :after => "chat_utterance.value='';". If you don't want to reset your entire form, you can just zilch out the one TEXTAREA. And my code zilches punitively, regardless if the submission worked.

New question: How to do that with either RJS and/or Unobtrusive JavaScript?

(Assuming raw JavaScript is, what, distasteful? :wink: