-
Notifications
You must be signed in to change notification settings - Fork 17
Home
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:
The plugin allows configuration particular to the adapter you’re using. Refer to the documentation for the individual adapters:
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
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.
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]$/"
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.