Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 client side validation

Since upgrading my site to Rails 4, the client-side-validations gem has stopped working for me. I have had a look at the various alternatives such as jquery-validation-rails and judge, which involve writing quite a bit of javascript, especially for a site so large. And in the case of jquery-validation-rails, re-doing all the validation rules client side. Considering Rails is such a popular framework, it surprises me that there is no 'easy' option. Is there any gem which anyone else is aware of, which does validation as well as the client-side-validation gem?

Or is the best alternative to use the ModelName.validators method mixed with some ajax, and do the validation through the jquery-validation-rails gem?

like image 488
tblakey89 Avatar asked Jan 10 '14 17:01

tblakey89


People also ask

What is the client side validation?

Client-side validation is an initial check and an important feature of good user experience; by catching invalid data on the client-side, the user can fix it straight away.

How does validation work in Rails?

Before saving an Active Record object, Rails runs your validations. If these validations produce any errors, Rails does not save the object. After Active Record has performed validations, any errors found can be accessed through the errors instance method, which returns a collection of errors.

What is server side validation with example?

The user input validation that takes place on the server side during a post back session is called server-side validation. The languages such as PHP and ASP.Net use server-side validation. Once the validation process on server side is over, the feedback is sent back to client by generating a new and dynamic web page.


3 Answers

From the Google.

http://rubygems.org/gems/rails4_client_side_validations

https://github.com/amatsuda/html5_validators

Also this guy seemed to have gotten the same gem you are using to work by using the 4-0-beta branch.

Client Side Validations and Rails4

If the 4-0-beta branch works for you, consider helping to maintain the gem to keep it alive.

To use a certain git repo version in your Gemfile:

gem 'client-side-validations', :git => 'https://github.com/bcardarella/client_side_validations/tree/4-0-beta'
like image 116
Beartech Avatar answered Sep 20 '22 14:09

Beartech


While the client side validations will work for the simple cases, they'll require an enormous amount of workarounds to work with more complicated scenarios (for instance - conditional validations). I would recommend using Judge instead, which give you more control.

like image 35
Roman Avatar answered Sep 17 '22 14:09

Roman


I was able to use a fork of the original client_side_vlaidations that is very active at the moment. I am using the latest version of simple_form, rails 4.1.8, and this client_side_validations. Simple setup with basic config.

like image 22
prodigerati Avatar answered Sep 19 '22 14:09

prodigerati