0

Open Modal is working fine, but not close modal. Here my files:

in 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 working, text appears in console.

A few resources amongst others I already considered: bootstrap modal popup not closing [https://stackoverflow.com/questions/16598213/how-to-bind-events-on-ajax-loaded-content][2] [https://stackoverflow.com/questions/52797328/rails-bootstrap-modal-not-closing][3]

Phipsen
  • 159
  • 3
  • 15

1 Answers1

0

After a long odyssey of searching, trial'n'error, I found out that the following jQuery plugin in application.js was causing the bootstrap modal not working properly:

import "tablednd/js/jquery.tablednd"

Once commented out, the modal was working as desired. Will now look for another solution. Hope this might prevent others from losing valuable time (weeks) solving such a 'stupid' error.

A question: Does one have to be careful with jQuery-Plugins?

Phipsen
  • 159
  • 3
  • 15