Client Side Validations and Rails4

Mohammad Abu Musa picture Mohammad Abu Musa · Jul 14, 2013 · Viewed 8.3k times · Source

I integrated client side validations with rails4 using the new branches available using the following gems

gem 'simple_form', '~> 3.0.0.rc'
gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta"
gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git'
gem "jquery-rails"

I also added the required JavaScript as the following

//= require jquery
//= require jquery_ujs
//= require foundation
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .
//= require_self

I created this test form in order to see if it works

= simple_form_for(@post, :validate => true) do |f|
  = f.error_notification

  .form-inputs
    = f.input :title, :required => true

  .form-actions
    = f.button :submit

of course in the model, it was

validates :title, presence: true

The problem is I can't figure our why it is not working, while JavaScript Console shows the following error:

Uncaught TypeError: Cannot read property 'add' of undefined

Answer

Nikhil Nanjappa picture Nikhil Nanjappa · Jan 27, 2014

These gems involve a lot of configurations and ordering to be proper. Instead of explaining the whole procedure i can give you a link in SO where a similar problem was solved. Please do check it out and follow the same.

ruby-on-rails client_side_validation simple_form javascript error

Hope it helped !