Rails 3: the gem of client_side_validations and password development

I have a customer_side_validations gem that works fine on my forms. I use Devise to model my users, and when I go to the edit_user_registration form, checks are set for everything except the fields: current_password ,: password and: password_confirmation.

In the case of formatting, I leave an empty mailbox, validation appears when I exit the field. However, if I leave the current_password field empty and nothing happens, then when I submit the form, I get the error message "1 error prevented this user from saving: password cannot be empty"

Thanks for any help

http://pastie.org/1907464

+6
source share
3 answers

ClientSideValidations will currently filter out any conditional validators. Devise sets some of the validators as conditional: https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb#L24-32

The reason I did this is because there is no good way for a client to determine the true meaning of this conditional. I could do this while creating the form, but what if this conditional value depends on the value that can be changed in the form? So I decided to filter them out and let things go back to the server.

It was an idea, but it is clear that it imposed unfair restrictions on some things. This is the most obvious (and popular).

Therefore, I plan to release a new version soon, which will allow you to explicitly override conditional filters. It will work as follows:

<%= f.text_field :password, :validate => { :presence => true, :confirmation => true } %> 

or

 <%= f.text_field :password, :validate => true %> 

In the first case, you can choose which validators to disable the filter. In the second case, it will disable the filter for all validators by this attribute. The conditional value will be evaluated during the creation of the form and, if it passes, will add a validator to the input element for use on the client.

+14
source

Lead branch now supports this format. Point your gemfile at it and you should be good

+4
source

Simply! Gem extends the default form builder of Rails, and all you have to do is set: validate => true option for any form_for tag (or simple_form_for for a simple form) for which you want built-in validations. The form builder uses some rail reflections on your models to generate some json that goes into the script tag after your form. Then json is used by the Javascript framework to perform the checks that need to be performed.

 <%= form_for(@user, :url => registration_path(resource_name), :validate => true) do |f| %> 
0
source

Source: https://habr.com/ru/post/888169/


All Articles