Skip to content


Subversion checkout URL

You can clone with
Download ZIP
validate form fields on the fly with formtastic
JavaScript Ruby
Latest commit 47c84b2 @liangzan Merge pull request #2 from qnm/patch-1.
Correcting the javsacript include name.
Failed to load latest commit information.
javascripts should be 0.1.4 instead
spec updated the specs. unashamed copying of formtastic specs
.gitignore ignoring tmp and log dirs
Gemfile bundler gemfiles
Gemfile.lock bundler gemfiles
LICENSE Initial commit to formtastic_validation.
README.textile Correcting the javsacript include name.
Rakefile added the changes in dependencies
VERSION Version bump to 0.1.4
formtastic_validation.gemspec regenerated the gemspec




Formtastic validation adds client side validation to your forms. Visit the demo app and its repo to see it in action.


  • works with existing formtastic code. no need to modify anything
  • javascript lib agnostic.
  • no AJAX that pounds your servers. its completely client side javascript
  • unobtrusive and very light weight



  $ gem install formtastic_validation

Remember to add the gem into your bundler Gemfile

Then run the generators to add the files on

From your rails root directory:

  $ rails generate formtastic_validation

This adds a configuration file to config/initializers and a couple of javascript files to public/javascripts

After that you need to add this to your application layout

    <%= javascript_include_tag 'livevalidation-1.3.min' %>
    <%= javascript_include_tag 'formtastic_validation-0.1.4.min' %>
    <script type="text/javascript">
      function initialize() {
          var formtasticValidation = new FormtasticValidation;
  <body onload="initialize()">

What the above does:

  • it included the livevalidation and formtastic_validation javascript files
  • it ran a function that instantiates a FormatasticValidation object and let it call initialize()


There is nothing to change in your existing code. You should see “Thankyou!” appearing next to fields which passed the validations. Forms which do not fufil the validations will fail to submit.

Validation options work.


The valid message can be changed in the formtastic_validation configuration file under config/initializers

CSS Styling

You can style the validation messages with the css selectors

.LV_validation_message { ... }   /* the validation message */
.LV_valid { ... }                /* for valid messages */
.LV_invalid { ... }              /* for invalid messages */


This gem is Rails 2 and 3 compatible.


Existing users need not change anything from the upgrade from rails 2 to 3.


Only the following validations work:

  1. validates_presence_of
  2. validates_acceptance_of
  3. validates_confirmation_of
  4. validates_exclusion_of
  5. validates_inclusion_of
  6. validates_numericality_of
  7. validates_format_of
  8. validates_length_of

validates_size_of does not work. Do use my fork of the validation_reflection gem for it to work.

The rest do not work as they depend on server queries.

Alternative implementations

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don’t break it in a
    future version unintentionally.
  • Commit, do not mess with rakefile, version, or history.
    (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.


Copyright © 2010 Wong Liang Zan. See LICENSE for details.

Something went wrong with that request. Please try again.