I\'m using Rails 3.1.0rc4 and client_side_validations 3.1.0. Everything works perfectly so long as the form is rendered in the main request. However, if the form itself is
Found the answer in the javascript source code for this gem:
// Main hook
// If new forms are dynamically introduced into the DOM the .validate() method
// must be invoked on that form
$(function() { $('form[data-validate]').validate(); })
So, in my particular case, I needed to do:
#jobs/new.js.erb
$('#form-job-new').append("<%= escape_javascript render(:file => 'jobs/new.html.erb') %>");
$('form[data-validate]').validate();
Depending on how much you use ujs (i do a lot) it might make more sense to do something like this instead of calling the validate method in every ujs file.
$('body').bind("ajax:success", function() {
if($('form[data-validate]').length){
$('form[data-validate]').validate();
}
});
or coffeescript
$("body").bind "ajax:success", ->
$("form[data-validate]").validate() if $("form[data-validate]").length