/validationgroup

Plugin to add conditional validation to Rails based on validation groups that can be enabled / disabled

Primary LanguageRubyMIT LicenseMIT

ValidationGroup
===============

When doing multipage forms that spread a models fields over several pages, validation becomes more difficult.  We would like to validate each step of the form, however, the rails validation run validation on all the fields.  This plugin enables you to define validation groups with certain fields, and then only run validation on those groups.

To install, type: git clone git://github.com/akira/validationgroup.git vendor/plugins/validationgroup && rm -rf vendor/plugins/validationgroup/.git

Home page for plugin is: http://alexkira.blogspot.com/2007/09/rails-validation-using-validation.html

Example
=======

class User < ActiveRecord::Base
  validates_presence_of :name, :description, :address, :email
  
  validation_group :step1, :fields=>[:name, :description]
  validation_group :step2, :fields=>[:address]     
end

This will run validation on :step1 fields
@user = User.new
@user.enable_validation_group :step1
@user.valid?

You can later disable validation groups by calling:
@user.disable_validation_group


Copyright (c) 2007 Alex Kira, released under the MIT license