Remote form with cancel

I want an AJAX form to become part of the page when an item is clicked (I have this part working.)

However, I am stumped at what should be really easy. I want my form to have a "save" and a "cancel" button.

I have the "save" button working just fine.

The "cancel" basically calls a "cancel" action that replaces the AJAX form with what was there. (or at least that is what it does in my head.)

Do I have to create a second form that only has the cancel button in it? Or do I need to style both buttons as links? Or is there a better way?

Thanks in advance,

Alan

Depending on what you want it to look like you can use either

link_to_remote 'text to display', :url=>...

or

button_to_function 'button text', :function=>remote_function(:url=>...)

In either case, the url refers to the action that will render your original block are remove the form.

This is probably obvious to everyone else, but I found what I thought was a VERY elegant solution to this problem: <div id=<%='"item:'+@item.id.to_s + '"' %>>   stuff I wanted to go away here... </div>

<input type="button" value="Cancel" <%= "onclick=$('item:" + @item.id.to_s + "').remove();" %>>

I am hope this is helpful to someone else....

--Alan