How to keep a Bootstrap Modal open even after a form submission

1,928 views
Skip to first unread message

Ron Chatterjee

unread,
Apr 27, 2016, 11:50:33 AM4/27/16
to web...@googlegroups.com
I am having problem keeping the Modal to stay  open an updated after the form submission. Searching on the web all I see is to set the backdrop (css) to static.  So, I changed the css on the link as: <a href="#" onclick="$('#myModal').modal({'backdrop': 'static'});" class="btn btn-primary">My Modal</a>

But the modal closes after the submission if I use the link. Same as button.


db.define_table("Education",
                Field("Title", "string", label='Title', requires=IS_NOT_EMPTY(),default=None),
                Field("filename", "upload",))


def index():
    form = SQLFORM(db.Education).process()
    return dict(form = form)


#index.html

{{extend 'layout.html'}}

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

    
  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>
              
              {{=form}}
              
          </p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
  
</div>

rajjm...@gmail.com

unread,
Apr 27, 2016, 4:55:08 PM4/27/16
to web2py-users
Try:

<script>
 $(function() { $('#myModal').modal('show'); });
</script>


On Wednesday, April 27, 2016 at 11:50:33 AM UTC-4, Ron Chatterjee wrote:
I am having problem keeping the Modal to stay  open an updated after the form submission. Searching on the web all I see is to set the backdrop (css) to static.  So, I changed the css on the link as: <a href="#" onclick="$('#myModal').modal({'backdrop': 'static'});" class="btn btn-primary">My Modal</a>

But the modal closes after the submission if I use the link. Same as button.


db.define_table("Education",
                Field("Title", "string", label='Title', requires=IS_NOT_EMPTY(),default=None),
                Field("filename", "upload", default=None, uploadfolder=os.path.join(request.folder, 'uploads')))

Ron Chatterjee

unread,
Apr 28, 2016, 1:35:05 PM4/28/16
to web...@googlegroups.com
The script above don't seem to work right. Do we have a javascript expert in this group? I pretty much want the modal to remain open like raj suggested and it works fine with his script, but don't want it to be open on load  when I go to index.html for the first time. But keep it open once clicked and submit every time. 



Reply all
Reply to author
Forward
0 new messages