最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Close Boostrap Modal AFTER form submit - Rails - Stack Overflow

programmeradmin2浏览0评论

I have a remote form in my rails app:

<%= form_for(@list_item, :remote => true) do |f| %>
  .............
  .............
  <%= f.submit("Add It!", class: "btn") %>
<% end %>

It's contained in a Bootstrap modal with id 'addListItem'. I want to dismiss this modal after submitting the form. I've found a few similar questions on SO, but none that has answered this in a way that prevents the form from submitting BEFORE the modal is closed. Help please?

I have a remote form in my rails app:

<%= form_for(@list_item, :remote => true) do |f| %>
  .............
  .............
  <%= f.submit("Add It!", class: "btn") %>
<% end %>

It's contained in a Bootstrap modal with id 'addListItem'. I want to dismiss this modal after submitting the form. I've found a few similar questions on SO, but none that has answered this in a way that prevents the form from submitting BEFORE the modal is closed. Help please?

Share Improve this question asked May 6, 2014 at 1:42 setthelinesettheline 3,3938 gold badges34 silver badges65 bronze badges 2
  • Are you responding w/ a js.erb template on your create action? – Helios de Guerra Commented May 6, 2014 at 2:28
  • No, there's nothing to update on the page. – settheline Commented May 6, 2014 at 3:13
Add a ment  | 

2 Answers 2

Reset to default 4

To dismiss the modal after form submit.

JavaScript

$('#form_id').on('submit', function() {
  $('#addListItem').modal('hide');
});

Add a click event on your submit button using jQuery:

$('.btn').click(function() {
  $('#addListItem').modal('toggle');
});
发布评论

评论列表(0)

  1. 暂无评论