Closed salmagomaa closed 7 years ago
Hi, For the unique problem, it should be done using a remote validator.
For the regex or format problem, It is an issue in client side validation gem. client side validation has a method called check_conditionals responsible for checking the conditions of the validation and check if it will be added to client side or not.
It returns true if the validation condition contains changed?
and Devise was checking for applying email validation using email_changed?
.
But it looks like now Devise using new Rails 5 syntax in validatable module it checks for the email validation using will_save_change_to_email?
.
So to fix the problem now you can add file in your initializers folder
config/initializers/client_side_validations/active_model.rb
and override the method like this:
# frozen_string_literal: true
require 'client_side_validations/core_ext'
require 'client_side_validations/extender'
require 'client_side_validations/active_model/conditionals'
module ClientSideValidations
module ActiveModel
module Validations
include ClientSideValidations::ActiveModel::Conditionals
def check_conditionals(attr, validator, force)
return true if validator.options[:if] && (validator.options[:if] =~ /changed\?/ || validator.options[:if] =~ /\Awill_save_change_to/)
result = can_force_validator?(attr, validator, force)
if validator.options[:if]
result &&= run_conditionals(validator.options[:if], :if)
end
if validator.options[:unless]
result &&= run_conditionals(validator.options[:unless], :unless)
end
result
end
end
end
end
And I am currently working in a PR to fix this issue in client_side_validation gem.
I'm closing this because it seems like it was fixed in the client_side_validations
. Please reopen if necessary.
Thanks
Version of Devise: 4.3.0 Version of ClientSideValidations: 9.3.3 Version of Rails: 5.1.1 User model:
The template form code:
Result: On blurring the email's input field, an error only shown if it is empty but if it already existed or if it has invalid format, no error is shown. I need the client_side_validations to be shown for all cases of the email errors, any help please??