Clearing TEXTAREA After AJAX Submit

Howdy,

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

On 11/17/06, Hunter H. [email protected] wrote:

<% form_remote_for(:chat_message, :url => chat_messages_path

Thanks,
H

Hunter,

Add an html id to your form_remote_for() and then in your RJS file:

page.call ‘Form.reset’, ‘your_form’

Hope this helps.


Zack C.
http://depixelate.com

Hunter H. 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:


Phlip