Plugin to add conditional validation to Rails based on validation groups that can be enabled / disabled
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tasks
test
.gitignore
CHANGELOG.rdoc
MIT-LICENSE
README.rdoc
Rakefile
init.rb
install.rb
uninstall.rb
validation_group-0.1.3.gem
validation_group.gemspec

README.rdoc

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.

Version: Rails 3. To use on Rails 2.x versions, use forked copy from github.com/jeffp/validationgroup

To install:

Add to your Gemfile:

gem 'validation_group'

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 © 2007 Alex Kira, released under the MIT license