free page hit counter

CleverValidation: Plugin for ruby on rails validation



1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Free Tools: Print This Post Print This Post 73 views

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

Share this post:

Del.icio.us Digg Technorati StumbleUpon

About the Author

admin

Leave a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>