【问题标题】:Cannot get the datepicker to work with Best in place rails 4无法让日期选择器与 Best in place rails 4 一起使用
【发布时间】:2017-01-26 16:18:50
【问题描述】:

我最适合处理常规输入字段。但是,我似乎无法让它与日期字段一起使用。

<%= best_in_place bedsheet_line, :sales_order, :class => "input_field", :html_attrs => {style: "width: 125px"} %> 等字段可以完美运行。

我无法工作的字段(即点击它没有反应)

查看代码为<%= best_in_place bedsheet_line, :start_time, :as => :date %>

我认为我需要将视图中字段上方的日期选择器初始化为

    <script>
        $.datepicker.setDefaults({
            dateFormat: 'yy-mm-dd'
        });

    </script>

in my application.html.erb, I have 

 <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <% javascript_include_tag  "http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" %>
  <% javascript_include_tag "http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"
      integrity="sha256-xNjb53/rY+WmG+4L6tTl9m6PpqknWZvRt0rO1SRnJzw="
      crossorigin="anonymous"%>

  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">

  <%= javascript_include_tag 'defaults' %>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


      <%= javascript_include_tag "best_in_place.js" %>

      <%= javascript_tag do %>
          $(document).ready(function() {
          /* Activating Best In Place */
          jQuery(".best_in_place").best_in_place();
          });
      <% end %>

如果我检查页面并查看控制台,当我尝试使用日期字段时会看到一些错误

ncaught TypeError: Cannot read property 'activateForm' of undefined
    at BestInPlaceEditor.bindForm (best_in_place.self-736c4c4….js?body=1:214)
    at BestInPlaceEditor (best_in_place.self-736c4c4….js?body=1:28)
    at setBestInPlace (best_in_place.self-736c4c4….js?body=1:648)
    at HTMLSpanElement.<anonymous> (best_in_place.self-736c4c4….js?body=1:661)
    at Function.each (jquery.self-4b58dfe….js?body=1:4)
    at init.each (jquery.self-4b58dfe….js?body=1:4)
    at init.jQuery.fn.best_in_place (best_in_place.self-736c4c4….js?body=1:660)
    at failed_logins.self-125cc80….js?body=1:3
    at HTMLDocument.<anonymous> (jquery.turbolinks.self-176b981….js?body=1:30)
    at HTMLDocument.dispatch (jquery.self-4b58dfe….js?body=

-------- 已编辑 -------------- -----

我尝试调用 datepicker 而不通过最佳位置,它可以工作。

我将&lt;p&gt;Date: &lt;input type="text" id="dp" onclick="$('#dp').datepicker();$('#dp').datepicker('show');"&gt;&lt;/p&gt;​ 放在我的视图中。

结果是出现一个字段并单击它会导致日期选择器日历弹出。

因此,jQuery 日期选择器在最佳位置之外工作。我的问题是我需要它与最佳日期字段一起工作。

【问题讨论】:

    标签: javascript jquery ruby-on-rails best-in-place


    【解决方案1】:

    已解决 - 尽管我在 application.js 中需要 best_in_place.jquery-ui,但我还需要将它作为 &lt;%= javascript_include_tag "best_in_place.jquery-ui" %&gt; 添加到我的 application.html.erb 中。

    现在日期和选择字段按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 2012-08-09
      • 2013-07-21
      • 2016-02-24
      相关资源
      最近更新 更多