際際滷

際際滷Share a Scribd company logo
By Hong ng Kh叩nh
Client Side Validations
Framgia Study Seminar
Using Client validation?
 Validation can occur as the form elements are completed and
before the form data is submitted to the server.
 Error recovery mechanism is quite simple as it guide the user
while filling up the form and ensures the user has filled the
required fields with valid data.
 A client-side input validation check can improve application
performance by catching malformed input on the client and,
therefore, saving a round-trip to the server.
Client validation gem
 I. Features
 II. Install
 III. Usage
I. Features
 Automatically extract and apply validation rules defined
on the server to the client.
 Validate nested fields
 Support custom validations
 Work with any ActiveModel::Validations based model
 Client side validation callbacks
 Support custom validations
 ..
II. Install
gem 'client_side_validations'
 rails g client_side_validations:install
 config/initializers/client_side_validations.rb
initializers/client_side_validations.rb
We need to add a validate: true option to the form_for
Custom Validators
 /app/models/user.rb
 validates :email, email_format: true
 when the email field loses the focus
/public/javascripts/rails.validations.custom.js
Refer
 http://railscasts.com/episodes/263-client-side-validations?view=
 https://github.com/bcardarella/client_side_validations/
Thank for listening

More Related Content

Client side validations gem - KhanhHD