bcardarella/client_side_validations — Issue #202: With form_for object,  :validate=> :true (rather than a boolean),  firebug spits out a "settings is undefined" error, but the form has the data-validate attribute
Author: csommerauer
Created: 2011-10-14 14:48:21+00:00
State: open

Obviously a symbol is not correct usage, but it is never caught and the form gets the attribute data-validate="true" set. The issue is that on the surface the form looks like it is working, but the validation javascript for the form is not generated and firebug then complains rightly about "settings is undefined"

I found the problem on this line:
https://github.com/bcardarella/client_side_validations/blob/master/lib/client_side_validations/action_view/form_helper.rb#L9
if options[:validate] is a symbol, then the variable content_for_name is going to pick it up as its value and you end up in this if statement
https://github.com/bcardarella/client_side_validations/blob/master/lib/client_side_validations/action_view/form_helper.rb#L33
and content_for(:true) will not do much good (unless you have a yield :true somewhere in your view) and the script variable is then assigned nil. form_for basically now returns "#{form}".html_safe instead of the intended "#{form}#{script}".html_safe. So you get the same form back without javascript.

I understand that this is a feature that allows moving javascript code into the header.

Could I suggest that the use of :true should not be permitted? Either raise an error or don't set the data-validate attribute.

This would save symbol/boolean dyslexics like myself a lot of time (too late for me though).
Thank you for your consideration.