title: Displaying errors when a Twitter Bootstrap modal window contains a Rails form helper
body: <p><strong>I'm asking about using a Twitter Bootstrap modal window with a Rails form helper and displaying form validation error messages. I'm using Twitter Bootstrap 2.0 with Rails 3.2.</strong></p>
  
  <p>I've got a form inside a Twitter Bootstrap modal window. There's a button on the page to open the modal window and display the form. All good, except when the form is submitted with errors, the page is displayed and error messages can't be seen because the form is inside the (initially undisplayed) modal window.</p>
  
  <p>I need to use jQuery to test if the form contains a Rails error message and override the "display: none;" style (or toggle the modal window to display) when the page is rendered.</p>
  
  <p>I've tried adding the following code to my assets/javascripts/application.js file but it doesn't work:</p>
  
  <pre><code>$('document').ready(function() {
    if ($('#error_explanation').length &gt; 0) {
      $("#request_invite").css("display", "block");
    }
  })
  </code></pre>
  
  <p>and also:</p>
  
  <pre><code>$('document').ready(function() {
    if ($('#error_explanation').length &gt; 0) {
      $("#request_invite").modal('toggle');
    }
  })
  </code></pre>
  
  <p><strong>What do I need to do to display the modal window or toggle it open when there's an error message present?</strong></p>
  
  <p>Here's the code that displays the form inside the Twitter Bootstrap modal window (Haml):</p>
  
  <pre><code>#request-invite.modal{:style =&gt; "display: none;"}
    = form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f|
      .modal-header
        %a.close{"data-dismiss" =&gt; "modal"} ×
        %h3 Request Invitation
      .modal-body
        - if @user.errors.any?
          #error_explanation
            %ul
              - @user.errors.full_messages.each do |msg|
                %li= msg
        %p
          = f.label :email
          %br/
          = f.email_field :email
      .modal-footer
        = f.submit "Request Invitation", :class =&gt; "btn.btn-success"
        %a.btn{"data-dismiss" =&gt; "modal", :href =&gt; "#"} Close
  #romance-copy{:style =&gt; "text-align: center; margin-top: 100px"}
    %h2 Want in?
  #call-to-action{:style =&gt; "text-align: center; margin-top: 100px"}
    %a.btn.btn-primary.btn-large{"data-toggle" =&gt; "modal", :href =&gt; "#request-invite"} Request invite
  </code></pre>