CleverValidation: Plugin for ruby on rails validation
CleverValidation is an extension to the existing rails validation methods that includes the ability to customize your validation error messages and features javascript functionality for adding a bit of interaction to your validations via scriptaculous effects.
Repository: git://github.com/two2twelve/clever_validation.git
Usage Example
Use this plugin in the exact manner you would use the default error_messages_for method. A basic example would be:
<%= clever_validation_for 'your_model_name', :title => "Sorry, we encountered some errors during your submission.",
:sub_title => "The errors in question are listed below...",
:effect => "pulsate" %>
This will display the error messages and a “show me” link next to each error, when clicked, it will scroll a user to the field in question and do the defined effect to it (in this case Effect.pulsate).
The available effects are:
- Pulsate
- Shake
- Highlight
- highlight_color
- duration
An example with the highlight effect would be:
<%= clever_validation_for 'your_model_name', :title => "Sorry, we encountered some errors during your submission.",
:sub_title => "The errors in question are listed below...",
:effect => "highlight",
:highlight_color => "eaeaea",
:duration => 8 %>
NOTE: I’ve overwritten the default rails validation messages for the model validation methods, so you will need to completely define your messages (which, I think would be preferred). Such as:
validates_presence_of :file_name, :message => “This field can’t be blank.”
So the error will appear exactly as: “This field can’t be blank.”
Basic CSS Styles:
Here are some basic styles to get your started. Place these into your CSS stylesheet and tweak them as you wish.
div#cleverValidation {
background: #FFFF99;
padding: 10px;
position: relative;
}
div#cleverValidation ul{
list-style:none;
}
div#cleverValidation a#hideLink {
position: absolute;
top: 10px;
right: 10px;
}
div#cleverValidation a#showMeLink {}
Related Posts
Tags: CleverValidation, error_messages, javascript, rails validation methods, ror plugin, scriptaculous effects, validation
Viewed: 231 views
