Forum: Ruby on Rails clearing out submitted form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kevin T. (Guest)
on 2007-02-27 15:04
I'm trying to put together a basic blog application for fun, and I'm
using an RJS template to insert a new comment into existing comments.
The comment data is inserted, but the comment form at the bottom of the
page still contains the comment.  I tried to clear out the text from the
form this way:

page.insert_html :top, 'comments', :partial => 'show_comment'
page.replace_html 'blog_entry_comment_body', ''
page.replace_html 'blog_entry_comment_subject', ''

But this doesn't work either.  Any thoughts on how to clear out the form
contents after the comment is added?  The form looks like this:

<% form_remote_tag(:url => {:action => 'ajax_add_comment', :controller
=> 'Comment', :id => }) do %>

    <%= render :partial=>"comment/form" %>
    <%= submit_tag 'Add Comment' %>
<% end %>

Firefox may also be putting the data in the form, as part of it's
auto-completion functionality, I suppose.  Same behavior is present in

Thanks in advance,
Chris H. (Guest)
on 2007-02-27 16:28
(Received via mailing list)
> page.replace_html 'blog_entry_comment_body', ''
> page.replace_html 'blog_entry_comment_subject', ''

this isn't doing what you think it is doing.  it replaces the contents
of tags, not the values. (actually, replace_html will work on a
textarea, but will not on type="text" input)

you want to do something like:

# blog_entry_comment_body => textarea
page << "$('blog_entry_comment_body').value = ''"
# also works
#page.replace_html('blog_entry_comment_body', '')

# blog_entry_comment_subject => input type="text"
page << "$('blog_entry_comment_subject').value = ''"

you are submitting the form via ajax, so therefore the page is not
being 'reloaded' and thus firefox or IE is not auto-filing the forms
for you at this point because you never left the page.
Hamza K. (Guest)
on 2007-02-28 16:58
(Received via mailing list)
You can also use Collection Proxies in RJS  like so :'div textarea').each do |element|

This takes all of the text areas in a div and replaces the value.  You
could also use the div name like so :'#id_of_textarea_here').each do |element|

So if I had a <textarea id="id_of_textarea_here" ...

That should replace the value.

This topic is locked and can not be replied to.