Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Client-side validations for Ruby on Rails (using javascript library livevalidation.com)
branch: master

This branch is 3 commits ahead of porras:master

README.md

NOTE

This has been forked from porras's original plugin, which is no longer supported, and has had changes merged in from various other forks:

jbernab/livevalidation

shalott

Basics

LiveValidation is a plugin which allows automatic integration of your Rails application with Javascript library LiveValidation[http://www.livevalidation.com/]. This library implements client-side form validation and you can see a demo in its site.

This plugin generates the needed Javascript code to run client-side the validations you have already defined in your models (with Rails validation helpers) to run them server-side, and redefines form helpers to automaticaly include that Javascript code. You have not to write your validations twice so you can keep DRY. And if you have 1) used Rails validation helpers to validate your models, and 2) used Rails form helpers to create your forms, you only have to install this plugin to get your forms validated both server and client-side!

[Spanish[http://www.lacoctelera.com/porras/post/2007/10/12/plugin-livevalidation-rails]]

== A little HOWTO

  1. Install the plugin:

    $ script/plugin install git://github.com/porras/livevalidation.git

  2. Install Javascript and CSS files under public/, with this Rake task:

    $ rake livevalidation:install

    Remember including them in your headers, including Prototype too (as LiveValidation depends on it), this way (for example):

    <%= javascript_include_tag 'prototype', 'live_validation' %> <%= stylesheet_link_tag 'live_validation' %>

2a. Add internationalization configuration for plugin in config/enviroment.rb of your application

# LiveValidation Config config.i18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '', 'config', 'locales', '.{rb,yml}')]

  1. There is no step 3 ;) You only need to add validations to your models, and crete your forms using the Rails form helpers, something like this:

    <% form_for(:resource, :url => resources_path) do |f| %> <%= f.text_field :name %> [etc ...] <% end %>

You can disable live validation for a given field using :live => false:

<%= f.text_field :name, :live => false %>

You can also reverse this schema so the default is no validation, including this in your config/environment.rb:

ActionView::live_validations = false

and enabling it only for some fields:

<%= f.text_field :name, :live => true %>

== Supported validations

  • validates_presence_of
  • validates_numericallity_of
  • validates_format_of
  • validates_length_of
  • validates_confirmation_of

== Supported form helpers

  • text_field
  • text_area
  • password_field

== Author

Plugin written by {Sergio Gil}[http://www.lacoctelera.com/porras]. Mail me to sgilperez at gmail.com for bug reports, feature requests or any comment.

== License

LiveValidation is licensed under the terms of the {MIT License}[http://www.opensource.org/licenses/mit-license.php].

Copyright (c) 2007 Sergio Gil

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.