Rails bootstrap-datepicker-rails不工作 [英] Rails bootstrap-datepicker-rails not working

查看:215
本文介绍了Rails bootstrap-datepicker-rails不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails 3.2.19应用程序使用twitter-bootstrap-rails 2.2.6和bootstrap-datepicker-rails 1.3.0.2。

I have a Rails 3.2.19 app using twitter-bootstrap-rails 2.2.6 and bootstrap-datepicker-rails 1.3.0.2.

我试图得到

当我检查元素时,我看到以下内容:

When I inspect the element I see the following:

<input data-behaviour="datepicker" id="project_due_date" name="project[due_date]" size="30" type="text">

检查控制台时,我不会收到任何JS / Coffee错误。

When checking the console I do not receive any JS/Coffee errors.

这是我的代码:

projects.js.coffee

 $(document).on "focus", "[data-behaviour~='datepicker']", (e) ->
 - $(this).datepicker
 - format: "yyyy-mm-dd"
 - weekStart: 1
 - autoclose: true

projects / _form.html.erb

<%= form_for(@project, :html => { :class => "well"}) do |f|  %>
 <% if @project.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@project.errors.count, "error") %> prohibited this contact from being created:</h2>

      <ul>
      <% @project.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.label :project_name %>
  <%= f.text_field :project_name, placeholder: "Build Spreadsheet", required: true %>
  <%= f.label :project_manager %>
  <%= f.collection_select(:user_id, User.all, :id, :full_name)%>
  <%= f.label :due_date %>
  <%= f.text_field :due_date, 'data-behaviour' => 'datepicker' %>
  </br>
<%= f.button :submit, :class => 'btn btn-info' %>
  <% end %>

我也试过根据id调用它,没有运气。我在Chrome,Firefox或Safari中看到相同的行为。

I've tried also calling it based on id and have had no luck. I see the same behavior in Chrome, Firefox, or Safari.

非常感谢任何帮助。

推荐答案

看起来我的CoffeeScript是错误的。我将其更改为以下内容:

It looks like my CoffeeScript was wrong. I changed it to the following:

$ ->
  $('[data-behaviour~=datepicker]').datepicker(format: "yyyy-mm-dd", autoclose: true)

现在我可以选择字段,日期选择器就会出现。

Now I'm able to select the field and the datepicker comes up.

这篇关于Rails bootstrap-datepicker-rails不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆