Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
holman edited this page Sep 12, 2010 · 16 revisions

Work-in-progress documentation. Feel free to edit at will.

In an ideal world, this plugin works out of the box. There are a few things to be aware of, though. Here you go:

Configuration

The plugin allows configuration particular to the adapter you’re using. Refer to the documentation for the individual adapters:

Setting Defaults: environment.rb

There are currently two defaults you can set for app-wide validation in your environment.rb file: default_valid_message and validate_on_blur. default_valid_message accepts a value for showing your user when their data passes validation, and validate_on_blur is a boolean that determines when validation occurs. A setting of true means we validate on blur, after the user has tabbed out of the input, and a setting of false (the default) validates live as she types. For example:


LiveValidations.use :livevalidation_dot_com, :default_valid_message => 'Thanks!', :validate_on_blur => true

validates_uniqueness_of: Making it work

Because your database is the only place where you can ask for uniqueness, this feature requires a controller callback. If you run a version of Rails older than 2.3, you will have to run the following command:

ruby script/generate live_validator

That’s because plugins couldn’t do controllers very easily back then. This adds a controller in your app/ folder, and adds some stuff to routes.rb.

validates_format_of: Regular expression handling

The regexp provided in your model will be displayed as-is to the javascripts. The plugin does not do anything to try to cope with differences between Ruby and JS regular expressions, so you can specify a JS specific regexp with the :live_validator option. A semi-sensible example:

validates_format_of :foo, :with => /\A[a-z]\z/, :live_validator => "/^[a-z]$/"

Validation messages

The plugin will ask the I18n library for validation messages. If you specify :message in your validation, this message will be used. Interpolating {model} is supported (such as :message => "is not as {model} as you might think"). Other I18n interpolations such as {{value}} and {{attribute}} is not supported.

Clone this wiki locally