繁体   English   中英

Rails 6 Bootstrap 4 Modal在提交时未关闭

[英]Rails 6 Bootstrap 4 Modal not closing on submit

打开模式工作正常,但不是关闭模式。 这是我的文件:

client.haml (客户端布局)

= link_to t('.mail to admin'), blame_path(@admin), remote: true  

路线.rb

get  "blame/:admin",     to: 'pages#blame', as: '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');
});

console.log("link clicked"); 正在工作,文本出现在控制台中。

我已经考虑过的一些资源: 引导模式弹出窗口未关闭[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]

经过长时间的搜索,反复试验,我发现application.js中的以下 jQuery 插件导致引导模式无法正常工作:

import "tablednd/js/jquery.tablednd"

一旦被注释掉,模态就会按预期工作。 现在将寻找另一种解决方案。 希望这可以防止其他人浪费宝贵的时间(几周)来解决这种“愚蠢”的错误。

一个问题:是否必须小心使用 jQuery 插件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM