GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A port of Ojay.Forms to Prototype, with a Rails plugin to generate client-side validation code
Clone URL: git://github.com/jcoglan/acceptance.git
name age message
file MIT-LICENSE Wed Apr 09 13:55:55 -0700 2008 Initial import, including the DSL classes from ... [jcoglan]
file README Fri Apr 11 06:48:23 -0700 2008 Fixing more typos. [jcoglan]
file Rakefile Fri Apr 11 03:36:28 -0700 2008 Updates from Ojay.Forms. Implementing displayEr... [jcoglan]
file init.rb Thu Apr 10 06:27:26 -0700 2008 Adding wrapper for validates_presence_of and ho... [jcoglan]
file install.rb Fri Apr 11 03:54:48 -0700 2008 Making the install hook a bit more friendly. [jcoglan]
directory javascripts/ Tue Jul 15 02:02:08 -0700 2008 Unix line endings. [jcoglan]
directory lib/ Mon Sep 01 05:00:31 -0700 2008 Rules array was shared by all ActiveRecord::Bas... [jcoglan]
directory tasks/ Wed Apr 09 13:55:55 -0700 2008 Initial import, including the DSL classes from ... [jcoglan]
directory test/ Tue Jul 15 02:02:08 -0700 2008 Unix line endings. [jcoglan]
file uninstall.rb Wed Apr 09 13:55:55 -0700 2008 Initial import, including the DSL classes from ... [jcoglan]
README
== Acceptance

Copyright (c) 2008 James Coglan, released under the MIT license

Acceptance is a port of the Ojay.Forms validation API to work with the Prototype library. This
plugin provides hooks into your Rails application that can automatically generate client-side
validation code from your Rails models. Information on the client-side API can be found at
the Ojay project site:

  http://ojay.othermedia.org/articles/forms.html

The only difference here is that you need to call <tt>Acceptance()</tt> instead of <tt>Ojay.Forms()</tt>
when using the API. All the other function calls are identical. For example:

  Acceptance(function() { with(this) {
    form('the-form')
      .requires('username').toHaveLength({minimum: 6})
      .expects('email_confirmation').toConfirm('email');
  }});

Refer to the Ojay site for the rest of the API. You can use this plugin with the original Ojay
client-side library by putting this in your environment.rb:

  Acceptance.adapter = :ojay

To have Acceptance generate client-side code for you, simply replace any calls to +form_for+
with +acceptance_form_for+. A script tag will be added after the form containing rules for
any fields in the form that can be checked client-side without making a server request.

  # Before
  <% form_for(@user) do |f| %> ... <% end %>
  
  # After
  <% acceptance_form_for(@user) do |f| %> ... <% end %>

The following validation types are supported, with a few limitations:

  validates_acceptance_of
  validates_confirmation_of
  validates_exclusion_of
  validates_format_of
  validates_inclusion_of
  validates_length_of
  validates_numericality_of
  validates_presence_of
  validates_size_of