15

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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
tblakey89
  • 656
  • 2
  • 9
  • 18

5 Answers5

13

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'
Community
  • 1
  • 1
Beartech
  • 6,173
  • 1
  • 18
  • 41
10

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.

Roman
  • 13,100
  • 2
  • 47
  • 63
  • Nice link, thanks a lot. And it's compatible with `simple_form` too. :D – Vadorequest Mar 31 '14 at 11:51
  • @Vadorequest client_side_validations does not require an enormous amount of workaround for conditional validations. See my solution here: http://stackoverflow.com/questions/22906257/client-side-validation-is-not-working-while-applying-conditional-validation-in-r/22943098#22943098 Could you provide more details about how Judge handles conditional validations? I have looked at the documentation and see no mention of it, so I wonder what the advantage is when it comes to conditional validations. – Isaac Betesh Aug 11 '14 at 15:15
  • When the condition for validation is decided on the client side. As I said before - for the simple cases client_side_validations maybe fine, but for the more complicated, when there's quite a few business logic on the client side (and the world is going this direction), then it becomes pretty hard to handle. – Roman Aug 11 '14 at 17:29
  • Another important pooint is that client_side_validations isn't maintained anymore and is not a great gem since its changes some stuff in the server side and isn't compatible with judge for instance. – Vadorequest Aug 12 '14 at 08:10
  • Judge does not appear to be maintained anymore. Guess we have to do this sort of thing ourselves then. – stephenmurdoch Nov 22 '14 at 21:09
  • +1 on judge. Client Validations duplicates a lot of validation logic between client and server and is a bit more difficult with more complex validations – user2490003 Feb 28 '16 at 21:27
2

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.

prodigerati
  • 597
  • 8
  • 26
0

I know the question is old, but how about good old require: "require"?

For example in view:

<%= f.text_area :body, placeholder: "Write your review here...", class: "form-control", rows: "5", required: "required" %>
Boomerange
  • 616
  • 1
  • 10
  • 18
-1

If you are using Bootstrap Form for Rails, you can give bootstrap_validator_rails a try.

https://github.com/huynhquancam/bootstrap_validator_rails