ReefPointsBlog

ClientSideValidations 3.2 Released!

Brian Cardarella

I just released ClientSideValidations 3.2

This is a very big release for the gem, one that took way too much time to get done. I want to start by re-introducing people to the gem, what the value is, and what the changes for 3.2 are.

ClientSideValidations is just that, it will extract the validations from your model and apply them to your forms on the client. The README has more comprehensive instructions. But here is the quick guide:

Add rails.validation.js to your asset pipeline, then add :validate => true to your form like so:

1
<%= form_for @user, :validate => true do |f| %>

And that is it. If you have more complex validators or custom validators on your models then you can quickly support these as well.

Changes

Version 3.2 brings many changes to the gem. The first of which is that from this version on we will be following Semantic Versioning or trying our best to do so.

The next change, and the biggest backward-incompatible change, is that the support for SimpleForm, Formtastic, Mongoid, and MongoMapper have been removed. These have been put into their own plugins:

This will be the convetion from now on. The ClientSideValidations gem itself will only support Rails out of the box. If there are additional FormBuilders or ORMs that people need support for these will be done so via the plugins. This will allow for quicker bug fixes and less complexity in the core gem.

I have also released a gem for Turbolinks support. Turbolinks support will be part of the core gem for the next release (4.0).

There have been a significant number of bug fixes for this release. If you ran into a bug before odds are it is now resolved.

Procs are now fullow supported in ActiveModel validators, you just have to force the validation to evaluate:

1
<%= f.text_field, :validate => { :length => true } %>

I have also added a FormBuilder method for adding validations for attributes that are not being written to the form but may be added dynamically later:

1
<%= f.validate :age, :weight %>

This method can also take validator specific options.

JavaScript API Additions and Changes

The first major change is that data-validate="true" is no longer rendered on the inputs server-side. It is added to the input at run-time.

The second is the addition of some jQuery functions:

1
2
3
$(form or input).enableClientSideValidations();
$(form or input).disableClientSideValidations();
$(form).resetClientSideValidations();

Security

There have been some security fixes. Mostly around the Uniqueness middleware.

Backwards incompatiable changes

Please give the gem a try and let me know what you think!