Client Side Validations and Rails4

人走茶凉 提交于 2019-11-29 15:37:44

问题


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

回答1:


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 !




回答2:


The problem appear to be in the order of the javascript, just change the order it will work fine



来源:https://stackoverflow.com/questions/17635847/client-side-validations-and-rails4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!