Everything is working smoothly with Open Modal, but I am facing an issue with closing the modal. Here are the relevant files:
Inside client.haml (the client layout)
= link_to t('.mail to admin'), blame_path(@admin), remote: true
routes.rb
get "blame/:admin", to: 'pages#blame', as: 'blame'
blame.js.erb
$('#blamepoint').html("<%= j(render 'blame') %>");
$('#blame').modal('toggle');
_blame.haml
.modal#blame.fade.hide{tabindex: "-1"}
= form_with(url: admin_notify_path(@admin), method: "get", id: 'blameform') do
.modal-dialog
.modal-content
.modal-header
%h5.modal-title Send a message to vote admin
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
%span{"aria-hidden" => "true"} ×
.modal-body
.form-group
= label_tag :message
= text_field_tag :message, '', class: 'form-control'
%small.form-text.text-muted This text will not be published.
.modal-footer
%button.btn.btn-secondary{"data-dismiss" => "modal", type: "button"} Close
= submit_tag 'Send to admin', id: 'foo', class: 'btn btn-primary', 'data-toggle' => 'modal'
Javascript
$(document).on("click", '#foo', function(event) {
console.log("link clicked");
$('#blame').modal('toggle');
});
The
console.log("link clicked");
is functioning correctly, as the text appears in the console.
Here are a few resources I have looked into:
- bootstrap modal popup not closing
- how to bind events on ajax loaded content
- rails bootstrap modal not closing