Common Gotchas

Jack Desert edited this page Nov 26, 2013 · 5 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"

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)