Forum: Ruby on Rails Clearing text_field_tag -- Help PLEASE

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-04-20 17:51
(Received via mailing list)
I'm trying to clear the input fields on an Ajax form.  Unfortunately,
I've tried this just about every way I can
think of and instead of clearing the fields, it's clearing pretty much
the whole page.  I would ***really*** appreciate some help!

The page has a form that allows the entry of two fields.  The form
exists inside a <div> with id=entry.  When the user clicks the button, a
new line is added to the page inside a <div> with id=ingredient_list.
The user can add as many lines as they want.  I want to clear the fields
each time they click the button. What's happening instead is that the
entry <div> and everything above it on the page is getting wiped out.
The code is below.  Any ideas?

Thanks in advance,
Bill

--- Here's _entry_form.rhtml ---
<%= form_remote_tag(:update => 'ingredient_list',
          :url => {:action => :add_ingredient},
          :position => 'bottom',
          :after => {:action => :clear_entry}) %>
   Name:
   <%= text_field_tag :name %>
   Amount:
   <%= text_field_tag :qty %>
   <%= submit_tag 'Add Ingredient' %>
<%= end_form_tag %>

--- and here's the clear_entry action in the controller ----
def clear_entry
   render :update do |page|
      page.entry.name.value = ''
      page.entry.qty.value = ''
   end
end
This topic is locked and can not be replied to.