# Clear a form after an ajax create

**URL:** <https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322>\
**Category:** Rails\
**Created:** [July 2, 2007, 9:56am UTC](https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322 "2007-07-02T09:56:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [July 2, 2007, 9:56am UTC](https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322/1 "2007-07-02T09:56:07Z")

</div>

I’m just starting to play with rjs, I have an index page with a  
remote\_form\_for to create new items. That’s working. However, after  
the ajax updates my container, the input form needs to be cleared.  
I’m not sure how to do that

[http://pastie.caboo.se/75318](http://pastie.caboo.se/75318)

tia

linoj

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [July 2, 2007, 10:28am UTC](https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322/2 "2007-07-02T10:28:32Z")

</div>

> I’m just starting to play with rjs, I have an index page with a  
> remote\_form\_for to create new items. That’s working. However, after  
> the ajax updates my container, the input form needs to be cleared.  
> I’m not sure how to do that

Can you show the partial \_form …?

There is an error when you use @empty in this line:

> page.replace\_html ‘create\_form’, {:partial=\>‘form’, :object=\> @empty}

the @empty object is a Choice model and you are using it in your \_form  
partial like a Form object… ‘text\_field’ is not defined in a Choice  
object.

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [July 2, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322/3 "2007-07-02T18:28:37Z")

</div>

thank you, yes, I realize the empty Choice object is not correct, that  
is my question. I’m looking for suggestion how to clear the form  
fields from the rjs.

The \_form.html.erb is quite simple

**Prompt**  
 \<%= form.text\_field :prompt %\>

On Jul 2, 4:28 am, Moises D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [July 2, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/clear-a-form-after-an-ajax-create/108322/4 "2007-07-02T23:49:44Z")

</div>

> I’m looking for suggestion how to clear the form fields from the rjs.
> 
> The \_form.html.erb is quite simple
> 
> **Prompt**  
> \<%= form.text\_field :prompt %\>

Ok, you can do this using rjs… first mark the form with an html id  
(‘my\_form’). After, you can use in the rjs template something like this:

page[‘my\_form’].reset()
