在 2021 或 2022 年创建的新 Rails 7 应用程序,当我单击带有 的表单时data-turbo-confirm,不会显示警报消息。
<%= form_with url: root_path(), data: {\'turbo-confirm\': "Are you sure you want to submit this form?"},\n method: :delete do |f| %>\n <%= f.submit "Delete".html_safe, class: "delete-apple-button btn btn-primary btn-sm" %>\n<% end %>\n\n\n<br />\n<%= turbo_frame_tag "apples-list" do %>\n nothing has happened yet\n<% end %>\nRun Code Online (Sandbox Code Playgroud)\n\n页面加载到:
\n\n当您单击删除时,不会显示任何警报:
\n\n预期结果:\n\xe2\x80\xa2\xc2\xa0确认按钮操作的警报消息
\n实际结果:\n\xe2\x80\xa2 没有显示警报
\n我正在尝试在新的 Rails 7 应用程序上使用 Select2,但遇到的困难如下:
我已将其固定到导入映射中并像这样导入:
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "trix"
pin "@rails/actiontext", to: "actiontext.js"
pin "select2", to: "https://ga.jspm.io/npm:select2@4.1.0-rc.0/dist/js/select2.js"
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js"
Run Code Online (Sandbox Code Playgroud)
(最后两行是在我运行 bin/importmap pin select2 时添加的)
import "jquery";
import "select2";
import "@hotwired/turbo-rails";
import "controllers";
import "trix";
import "@rails/actiontext";
Run Code Online (Sandbox Code Playgroud)
(已将 jquery 和 select2 移至末尾和开头 - 没有改变任何事情)。
当我处于表单中时,我可以使用 $ 访问元素,如下所示:
$('#book_genre_ids');
...(returns the element)
Run Code Online (Sandbox Code Playgroud)
但是当我在控制台中手动尝试在元素上运行 select2() 时,会发生以下情况: …