views:

1248

answers:

4

I have my form and validation working great with regular http requests. I would like it to use AJAX. I know i can validate on the client side but that seems redundant given that I have defined the validations in my model.

As the user is filling out the form, I'd like to give feedback to them on their entries. What is the best way to use the rails defined validations in an AJAX form and give live feedback?

+3  A: 

Check out the live-validations plugin. There's also an introductory screencast.

Simone Carletti
Looks to be exactly what I need but when I script/plugin install it and add the option to the form for, I get an error when the server is booting:uninitialized constant LiveValidationsThoughts?
ChrisH
A: 

http://wiki.github.com/augustl/live-validations has installation instructions.

When you add LiveValidations.use :jquery_validations to the bottom of your environment.rb, make sure it is outside of the Rails::Initializer block.

Lee Edwards
+1  A: 

Live-validations was kinda messy to get working for me, so I started with my own solution from scratch backed by Validatious. It's actually really DRY because of the Rails conventions in the back that made it possible to do a lot of smart assumptions. In most cases, all you need is to include a few javascript dependencies and declare your validations in your models as always - and it all just works! =) Peep the README for details.

Here it is:

http://github.com/grimen/validatious-on-rails

grimen
A: 

If you're looking for a solution to this that does not introduce any plugin dependencies check out my screencast on the issue:

AJAX Validations on Rails 2.3.8

Emerson