ruby-on-rails - 日期选择器不适用于 bootstrap-modal

标签 ruby-on-rails bootstrap-modal

我正在尝试在 Rails 项目上实现引导模式。它工作正常,只是我的日期选择器不在模式内工作。在我的索引文件中,我有以下内容

<%= link_to "search_products", search_products_path, remote: true,  "data-toggle" => "modal", 
     'data-target' => '#search-products' %>

<div class="modal fade" id="search-products" tabindex="-1"  
    role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
      <div class="modal-content"></div>
  </div>
</div>

然后在 app/views/products/search_products.js.erb 中我有

 $("#search-products").html("<%= escape_javascript(render 'products/search_product') 
  %>")

在“search_product”部分内,

  <%= text_field_tag :date_purchased, type: "text", placeholder: t('click_here'), 
     class: "form-control date_picker" %>

我正在使用rails4 日期选择器不是来自 Bootstrap ,并且在我的应用程序的非模式页面中工作正常。如果有人能告诉我我做错了什么,我将不胜感激。

谢谢

最佳答案

在您的 app/views/products/search_products.js.erb 中,您还必须在将 HTML 动态添加到 DOM 中时显式初始化日期选择器。所以该文件应该看起来像这样(取决于您使用的日期选择器):

$("#search-products").html("<%= escape_javascript(render 'products/search_product') %>");
$(".date_picker").datepicker();

关于ruby-on-rails - 日期选择器不适用于 bootstrap-modal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26402188/

相关文章:

laravel - 如何使用模态 Laravel 5.8 更新特定行

javascript - 将变量传递给 Bootstrap 模式

javascript - Rails 中的 Bootstrap 4 模态表单禁用 ajax 刷新时的提交按钮

ruby-on-rails - 如何使用 Ruby New Relic 代理获取更详细的事务跟踪

ruby-on-rails - 数据库记录不保存/保留在 Rails 测试功能中?

ruby-on-rails - <NoMethodError:#<Record::ActiveRecord_Relation的未定义方法 `read_attribute_for_serialization':

css - 关闭引导模式后 img 无法正确显示

ruby-on-rails - 访问关联的关联

ruby-on-rails - rails : Validate uniqueness ignoring some records

javascript - 如何在 Bootstrap Modal 中显示 Canvas