Skip to content
Michal Remis edited this page Apr 10, 2020 · 8 revisions

":validate => true" vs. ":validate => :true"

It may sound obvious, but "form_for :validate => true" is different from "form_for :validate => :true" (note the symbol instead of true).

This is because when you pass a symbol to :validate it will assign the script to content_for so you can render the script tag elsewhere. (See https://github.com/bcardarella/client_side_validations/issues/98)

If you accidentally use :true instead of true your client side validations will not work, with the following error displayed in your browser's js error console.

"settings is undefined"

Use :symbol attribute names

When using f.text_field "name", despite field properly rendered, validations aren't loaded for this field. You have to use f.text_field :name

Conflicts with formatted_form

If the formatted_form gem is anywhere in your Gemfile.lock, your validations will not fire. This is because path_to_formatted_form_gem/lib/formatted_form/engine.rb has this line:

ActionView::Base.field_error_proc = proc { |input, instance| input }

which gets loaded after your config/initializers/client_side_validations.rb which also defines ActionView::Base.field_error_proc.

An (ugly) workaround is to require config/initializers/client_side_validations.rb the first time your controller is fired so that it gets last write.

(Note that formatted_form is a dependency of comfortable_mexican_sofa)