bootstrap日期选择器轨道无法通过带有bootstrap模式的simple_form工作

bootstrap-datepicker-rails not working via simple_form with bootstrap modal

本文关键字:bootstrap 模式 simple 工作 form 选择器 日期 轨道      更新时间:2024-05-18

我正试图让一个日期选择器(使用bootstrap日期选择器rails gem)通过具有bootstrap模式的simple_form进行显示,但没有成功。

我读过很多东西,比如:

https://github.com/Nerian/bootstrap-datepicker-rails/issues/51如何设置引导程序日期选择器轨道?http://learningnewtricks.wordpress.com/2013/07/03/bootstrap-date-picker-on-rails-so-simple/http://www.chadcf.com/blog/jqueryui-datepicker-rails-and-simpleform-easy-way

我得到的只是一个文本字段,但当我点击它时,没有日期选择器。可能是日期选择器在模式后面吗?如果是,如何解决?

我的设置如下:

fyousuf$ rails -v
Rails 3.2.12
fyousuf$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]

app/assets/stylesheets/application.css

    *= require_self
    *= require fullcalendar
    *= require bootstrap-datepicker
    *= require_tree .

app/assets/javascripts/application.js

    //= require jquery
    //= require jquery_ujs
    //= require twitter/bootstrap
    //= require bootstrap
    //= require fullcalendar
    //= require bootstrap-datepicker
    //= require_tree .

app/assets/javascript/s/events.js

    # Place all the behaviors and hooks related to the matching controller here.
    # All this logic will automatically be available in application.js.
    # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
    $('[data-behaviour~=datepicker]').datepicker({"format": "yyyy-mm-dd", "weekStart": 1,      "autoclose": true});

app/views/events/_form.html.erb

    <%= simple_form_for(@event) do |f| %>
        ...
        <%= f.input :starts_at, :as => :string, :input_html => { data: {behaviour: "datepicker"}} %>
        ...
    <% end %>

在我的视图中

= f.input :first_name
= f.input :last_name
= f.input :date_of_birth, as: :string, input_html: { class: "datepicker" }

在我的应用程序.js上

$(function() {
    $('input.datepicker').data({behaviour: "datepicker"}).datepicker();
});

我正在使用的版本

> bundle | grep bootstrap
Using bootstrap-datepicker-rails 1.3.0.2
Using twitter-bootstrap-rails 2.2.8

这对我来说非常有效。加载表单后,如果我点击输入"date_of_firth",就会出现日期选择器。