Ben
Ben

Reputation: 1963

The rails way of doing client side validation (Rails 4 with simple_form)

I am new to Rails and using Rails 4. I have started some forms for creating/editing some models and have added some validation which works fine on the server side.

I assumed that Rails would have something built in to handle client side validation - turns out it doesn't.

I have searched on google and found 'client_side_validation' which is no longer maintained and I don't think works in Rails 4 anyway.

There doesn't seem to be an obvious go to library for Rails client side validation. So what is the 'Rails way' of handling this? Roll your own? Duplicate the logic client side using jQuery? Use html5 validation and fall back to server side when it isn't their? Or is there a library (preferably one that works with simple_form) that I can just install and use?

Upvotes: 4

Views: 8548

Answers (4)

SSR
SSR

Reputation: 6438

Rails 4 + Simple form : To install "Client side validations" with simple_form successfully, you should check for latest versions direct from Github with latest branch.

The released gems don't work with Rails >= 4.0

gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations'
gem 'client_side_validations-simple_form', github: 'DavyJonesLocker/client_side_validations-simple_form'

Make sure your gem file does not use these versions

client-side Validation 3.2.5
client_side_validations-simple_form 2.1.0

These versions does not support rails 4.2.0

For more detail please check this link, https://github.com/DavyJonesLocker/client_side_validations-simple_form/issues/41

Upvotes: 2

prodigerati
prodigerati

Reputation: 607

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.

Upvotes: 0

S. A.
S. A.

Reputation: 3754

There is client_side_validations, but is not longer maintained. Probably the best way is using some jQuery plugin like jquery-validation.

Upvotes: 3

jjrgjbdmzkve
jjrgjbdmzkve

Reputation: 82

One way to achieve this is in Rails 4 is to use the client side validation gem: http://rubygems.org/gems/rails4_client_side_validations

This guy here is using it: Client Side Validations and Rails4

Railscasts provides a good tutorial (Rails 3) on it here: http://railscasts.com/episodes/263-client-side-validations

Upvotes: 1

Related Questions