AJAX Form, :postion => :bottom but replace when error?

I have a form below a table to add new notes to an item. If the note
does not have a title or body, the note is not saved and a form error
is displayed. However, if the note validates successfully, then the
note is added to the bottom of the table above. Just for reference,
the table id is “note_list” and the add form div is id=“note_add_form”.

So, my problem/question is. Upon success, I want to update note_list
appending to the bottom of the table, however, upon failure, I want
to replace note_list not append to the bottom of it.

I can do something like this:

:update => { :success => ‘note_list’, :failure =>
‘note_add_form’}, :position => :bottom

on my form tag and that works partially. When a note is added
successfully, it’s appended to the bottom of the table. However, when
a validation error occurs, the error message and a whole new form is
appended to the bottom of the existing form. If I fail again, the
note_add_form div will then have three forms, etc…

Is there a way to make this work?

Jeremy C.

Jeremy,

If you have a container div (or other structure) for note_add_form you
can
use rjs and something like:

page.replace ‘container_div_id’, 'html the you want to replace with
(i.e.

You broked it!
)'

Bryan

What if the content I want to place it with is the rendered template?
For instance:

	<%= error_messages_for 'note' %>

Jeremy

Jeremy C. wrote:

What if the content I want to place it with is the rendered template?
For instance:

  <%= error_messages_for 'note' %>

Jeremy

Put that in its own div?

-Matt