loading into a modal window via javascript turns off of the validations #339

eriko opened this Issue Jun 6, 2012 · 5 comments


None yet

4 participants


So I am loading form_for partials (straight action_view) in to modal (from twitter_bootstrap) using javascript. When I use the forms normally as just forms in a page the script tags gets added normally but if I load the rendered form_for partial into a modal via a new.js.erb the script tag does not get created. I have worked my way through action_view/form_helper.rb in the plugin it seems that something about

content_tag(:script) do
    "window['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators =>      'validator_hash').to_json};".html_safe

does not render the script tag as the call to client_side_form_settings returns an empty string.


I need more information. Are you rendering the form async via javascript? Can you provide some code?


I was loading form async via javascript using code like:

      <%= link_to "Link to existing wiki",
                  new_offering_wiki_url(offering_id, :sub_action => :link),
                  :remote => true,
                  :class => "btn" %>

I have stopped doing the clientside validation so I do not have the code at this point. I instrumented the plugin code pretty deep and what I found is that at the point I mentioned above script tag was or was not added based on if the rendered in a .html.erb or from .js.erb like :

$("#website_modal_holder").html("<%= escape_javascript(render("modal")) %>");
Had these problem too. The form partial was rendered using the above method then presented in a jquery-ui dialog.

Update: found a wiki article for this: https://github.com/bcardarella/client_side_validations/wiki/Validating-dynamically-added-forms


You will have to call


after any modal form loads. You should actually call it on the specific id of the form or scope the query to the modal window to ensure no other matching forms don't get picked up too.

@bcardarella bcardarella closed this Oct 2, 2012

@bcardarella I've same problem. I do this but returns this error:

TypeError: $(...).validate is not a function

My application.js

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require bootstrap
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment