grimen / validatious-on-rails

Rails plugin that maps model validations to class names on form elements to integrate with Validatious. IMPORTANT: Project is not maintained anymore.
MIT License
346 stars 13 forks source link

h1. VALIDATIOUS-ON-RAILS

Rails plugin that maps model validations to class names on form elements to integrate with Validatious.

h2. What Is Validatious?

Elevator pitch: A (kick-ass) unobtrusive client-side validation javascript library - the only one you'll ever need.

"http://validatious.org":http://validatious.org

h2. ...So What Is Validatious-On-Rails?

Elevator pitch: A (kick-ass) seamless "glue" between ActiveRecord and Validatious: Automatically maps models validations to client-side Validatious-validators - and when client-side won't work: Validatious-backed AJAX validators - on form elements in a obtrusive way using DOM classes. Makes your form-filling users happier, and you code cleaner and more scalable (tjing-tjing!). Why define client-side validations "once-again", when they already defined in the model?

h2. Features & Goals

h3. Current Features:

Note: This project is under heavy development; a lot of experimenting going on - things might change under the hood. See the "TODO":http://github.com/grimen/validatious-on-rails/blob/master/TODO for more info. Please help out file any issues/problems.

h3. Goals:

Note: Somethings fundamental is missing? Let me know! =)

h3. Known Issues

h2. Installation

Gem:

sudo gem install validatious-on-rails --source http://gemcutter.org

and in @config/environment.rb@:

config.gem 'validatious-on-rails', :source => 'http://gemcutter.org'

Plugin:

./script/plugin install git://github.com/grimen/validatious-on-rails.git

Dependencies:

Note: For testing, get: "context":http://github.com/jeremymcanally/context, "rr":http://github.com/btakita/rr, "acts_as_fu":http://github.com/nakajima/acts_as_fu, and "redgreen":http://gemcutter.org/gems/redgreen.

h2. Configuration

h3. 1. Generate required javascript files

$ ./script/generate v2
      create  config/initializers/validatious-on-rails.rb
      create  public/javascripts/XMLHttpRequest.js
      create  public/javascripts/v2.standalone.full.min.js
      create  public/javascripts/v2.config.js
      create  public/javascripts/v2.rails.js

Note: @./script/generate v2@ <=> @./script/generate validatious@

Important: It is very impostant that you do this (update these scripts) on each new gem release; especially @v2.rails@ will be a subject for change because this library contains kind of low level helpers to get Validatious and additional features such as AJAX validations to play. I'm not sure what might be added/removed in the future, but as long as you keep these updated you probably won't notice any difference.

h3. 2. Include the javascripts in your layout

@app/views/application.html.erb@ or similar:


  ...
  <%= javascript_include_tag 'XMLHttpRequest' ,'v2.standalone.full.min', 'v2.config', 'v2.rails' %>
  <%= javascript_for_validatious %>
  ...

Notes:

h2. Usage

Easy!

Consider you got some model validations:

class Post < ActiveRecord::Base
  validates_presence_of :title
  validates_uniqueness_of :title
  validates_length_of :title, :within => 3..20
  validates_length_of :body, :within => 3..20, :client_side => false
end

...then you now got working client-side validations for any forms with class @validate@ (or any custom class - see documentation/config):

<% form_for(@post, :html => {:class => 'validate'}) do |f| %>
  <%= f.text_field :title %>  # Validated performed using client-side. Note: uniqueness-check is performed using an AJAX-request.
  <%= f.text_area :body %>    # No client-side validation performed, i.e. ignored.
<% end %>

h2. Validatious ♥ Formtastic

For all you "Formtastic":http://github.com/justinfrench/formtastic users out there: This plugin is out-of-the-box compatible with Formtastic - unlike the similar solution(s) out there. But to get Validatious and Formtastic to play well with each other, you need to tweak the configuration settings a bit. These settings are very much recommended:

Formtastic:

Formtastic::SemanticFormBuilder.inline_errors = :list
Formtastic::SemanticFormBuilder.inline_order  = [:input, :hints, :errors]

Validatious:

v2.Field.prototype.positionErrorsAbove = false;
v2.Fieldset.prototype.positionErrorsAbove = false;
v2.Fieldset.prototype.messagesClass = 'errors';
v2.Fieldset.prototype.failureClass = 'error';
v2.Fieldset.prototype.successClass = '';
v2.Field.prototype.messagesClass = 'errors';
v2.Field.prototype.failureClass = 'error';
v2.Field.prototype.successClass = '';

Actually, Validatious errors can be tweaked to work with any form builder/markup, but how that is done is out of context for this plugin. For more info; checkout the documentation for the "Validatious Reporting extension":http://validatious.org/learn/features/reporting.

h2. Limitations

This is very much work-in-progress, so there are some known limitations that should work very soon. See "TODO":http://github.com/grimen/validatious-on-rails/blob/master/TODO.

h2. Origin

This project was originally forked from:

"http://github.com/cjohansen/validatious-on-rails":http://github.com/cjohansen/validatious-on-rails

h2. License

Original work:

Released under the MIT license.
Copyright (c) 2008 "Christian Johansen":http://github.com/cjohansen

Additional work:

Released under the MIT license.
Copyright (c) 2009 "Jonas Grimfelt":http://github.com/grimen

!https://d2weczhvl823v0.cloudfront.net/grimen/validatious-on-rails/trend.png(Bitdeli Badge)!:https://bitdeli.com/free