Using Devise

gaaady edited this page Sep 18, 2011 · 9 revisions

The validators Devise puts on your models are set with conditionals. ClientSideValidations will filter out all validators with conditionals by default, so you will need to override the conditional in your form.

For the default Rails form helpers:

<%= form_for @user, :validate => true do |u| %>
  <%= u.text_field :email, :validate => true %>
<% end %>

Please note the different sytnax if you are using SimpleForm or Formtastic.

In addition to changing your form view, the default regular expression for matching emails that Devise uses is not compatible with Javascript. To fix the problem, you will have to roll your own regular expression for matching emails like this (notice the :email_regexp option that has been added to the default model):

# app/models/user.rb
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :email_regexp =>  /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

For using client_side_validations with devise forms displayed by alternate controllers, such as on your home page, see here.

see more information here : http://stackoverflow.com/questions/6012428/rails-3-client-side-validations-gem-and-devise-password-validations/6040520#6040520