javascript - Rails 6 Bootstrap 4 Modal在提交时未关闭
问题描述
打开模式工作正常,但不是关闭模式。这是我的文件:
在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]
解决方案
经过长时间的搜索,try'n'error,我发现以下 jQuery 插件application.js
导致引导模式无法正常工作:
import "tablednd/js/jquery.tablednd"
一旦被注释掉,模态就会按预期工作。现在将寻找另一种解决方案。希望这可以防止其他人浪费宝贵的时间(几周)来解决这种“愚蠢”的错误。
一个问题:是否必须小心使用 jQuery 插件?
推荐阅读
- r - 使用 RcppAlgos (R),是否有一个函数可以获取结果组合中元素的索引?
- spring - 未为 PasswordCompareConfigurer 类型定义 contextSource()?
- ios - 如何为 Google 登录委托功能进行单元测试?
- python - Sympy 潜艇没有价值
- ruby-on-rails - Ruby on rails Validation 不适用于包含 Action 文本等的 Form 对象
- python - 使用 Python 库地址标准化地址
- elasticsearch - Elasticsearch 突出显示的术语各不相同
- java - 从 Android (java) 到 Spring Boot 的日期格式
- shopify - 液体编码(Shopify)“and”和“elsif”不能一起工作
- react-native - 如何在 React Native 应用程序的 Cognito 用户池中搜索用户