Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:17:38+00:00 2026-06-18T15:17:38+00:00

I have a Modal with form and after submitting it with no validation error

  • 0

I have a Modal with form and after submitting it with no validation error i’m trying to close Modal and refresh page with new results. But i can’t get it to work. I have this code (Rails 3):

My Controller:

    def create

    @stuff = Stuff.new(params[:stuff])

       respond_to do |format|
          if @stuff.save
             format.js 
          else
             format.js
          end
       end
     end

_addModal.html.erb

<div id="addModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Label</h3>
    </div>
        <div class="modal-body">
            <p>
                <fieldset>
                <label></label>
                <%= render 'form2' %>    
                </fieldset>
            </p>
        </div>
    </div>

_form2.html.erb

%= form_for(@stuff, :remote => true) do |f| %>

   <% if @stuff.errors.any? %>
     <div id="error_explanation">
       <div class="alert">
          <h2><%= @stuff.errors.count %></h2>

        <ul>
          <% @stuff.errors.full_messages.each do |msg| %>
           <li><%= msg %></li>
          <% end %>
        </ul>
            </div>
          </div>
               <% end %>

     <%= f.label :name %><br />
     <%= f.text_field :name %>


    <%= f.submit %>

  <% end %>

create.js.erb

<%- if @stuff.errors.any? %>

           $('#addModal').html('<%= escape_javascript(render :partial => "form2") %>');

           <%- else %>

          $('#addModal').modal('hide').empty();


          <%- end %>

Any ideas how I can get this to work?

Thanks!

Update:

Also i got few quetions:
1) In case there are validation errors create.js.erb returns new Modal with ‘form2’ content only- without #addModal layout. How can i fix it?

2) How can clear form after successful submision?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:17:40+00:00Added an answer on June 18, 2026 at 3:17 pm

    add this in your js.erb file to reload the page automatically

    <%- if @stuff.errors.any? %>
      $('#addModal').html('<%= escape_javascript(render :partial => "form2") %>');
    <%- else %>
      $('#addModal').modal('hide').empty();
      window.location.reload();
    <%- end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple modal form which I'd like to close when Esc is
I have a main form and non-modal autocomplete form. How can I prevent the
I have a modal with a form and after i submit the form I
I'm getting an ActiveRecord error after submitting a form for a table called worequests.
I have a modal dialog box with form. I want to reload the page
I had this simple modal contact form working fine but must have broke it
I have an app that opens a non-modal form from the main form. The
I have a modal dialog where I place the contents of an html form
on my web site I want to have login/registration form in modal window done
I have a form that is brought up in a ajaxed modal which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.