Rapscallion - Ruby on Rails Client Side Validations Gem
Add this line to application.js:
//= require rapscallion/validations
Activate with Javascript:
$('.validate_me').rapscallion();
Options:
Change class of error message div
errormessagecontainerclass: “errormessages”Set a class on field with error
fieldwitherrorclass: ‘haserror’Set a class on field with success
fieldvalidclass: ‘is_valid’Container for input – used to add and remove error messages
field_container: ‘div.input’Event that triggers validation
trigger: ‘blur’
eg $(‘.rapscallion’).rapscallion({errormessagecontainerclass: ‘errors’, fieldcontainer: ‘.field’})
Add this line to Gemfile:
gem 'rapscallion'
Input example with Simple Form:
.input
= f.input :username, input_html: {class: 'rapscallion'}
Modify form tag when validating an existing record (for example to avoid uniqueness validation problems):
= simple_form_for @thing, html: {data: {existing_record: @thing.id}} do |f|
Add validations in model as you normally would:
class User < ActiveRecord::Base
validate :username, presence: true
end