# RJS form validation

**URL:** <https://www.ruby-forum.com/t/rjs-form-validation/156490>\
**Category:** Rails\
**Created:** [December 28, 2008, 10:16pm UTC](https://www.ruby-forum.com/t/rjs-form-validation/156490 "2008-12-28T22:16:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [December 28, 2008, 10:16pm UTC](https://www.ruby-forum.com/t/rjs-form-validation/156490/1 "2008-12-28T22:16:36Z")

</div>

Hi.

I’m trying to add and validate objects using RJS.

I have a page where if a user clicks on a link a form partial is  
inserted via javascript(depending on the click).

If that form is valid I would like to remove it and display the  
object, otherwise rewrite the form with the errors inline(next to each  
field).

I’m stuck at the point where I don’t know how to rewrite the form. On  
the first insert the div with the form has no unique id(since a user  
can click multiple times and insert multiple forms, and I need the  
update the proper one).

My stupid idea is to generate a random number and pass that as an id  
to the div form and via hidden\_field so I know what to remove/update.

I’m sure there has to be a better way. I’ve been looking for tutorials  
but I haven’t found something specifically for what I want to do.

–  
M.
