Clearing a remote form

I’m using a form_remote_tag to create an ajax form, but would like to
clear the values in the fields after submitting the form. Is there a
way to do this that I am missing or am I going to have to write my own
javascript to do it?


Sterling A.
sterling [at] sterlinganderson.net
http://sterlinganderson.net/
608.239.8387

Sterling,

The simplest approach I’ve found is to redraw the form. I’m assuming
you’ve got some kind of rjs file to facilitate returning error
messages, etc. Make sure the form is inside a div tag that has a
unique id and then if the form is submitted succesfully execute a

page.replace “unique-id”, :partial => ‘form_partial’

You could theoretically save yourself a small amount of bandwidth by
writing some custom javascript, but the cost of loading that javascript
on every page load will likely be close to the load created by
refreshing the entire form. (assuming the form isn’t too large)

Try the :loading => “this.reset();” option, or :loaded, :completed,
:after
etc depending on when exactly you want it cleared.

Hi Sterling,

Sterling A. wrote:\

I’m using a form_remote_tag to create an ajax form,
but would like to clear the values in the fields after
submitting the form.

If you’re using Ajax to submit your form (as suggested) you can just use
page.form.reset(‘name_your_form’)

hth,
Bill

What also works with AJAX:

:success => “Form.reset(‘HTML ID OF FORM’)”

–Lars