簡體   English   中英

bootstrap-datepicker-rails無法通過帶引導模式的simple_form工作

[英]bootstrap-datepicker-rails not working via simple_form with bootstrap modal

我試圖通過帶引導模式的 simple_form顯示一個datepicker (使用bootstrap-datepicker-rails gem ),但沒有運氣。

我讀了很多東西,比如:

https://github.com/Nerian/bootstrap-datepicker-rails/issues/51 如何設置bootstrap-datepicker-rails? http://learningnewtricks.wordpress.com/2013/07/03/bootstrap-date-picker-on-rails-so-simple/ http://www.chadcf.com/blog/jqueryui-datepicker-rails-and- simpleform易路

我得到的只是一個文本字段,但當我點擊它時,沒有日期選擇器。 可能是日期選擇器背后的模態,如果是這樣如何解決?

我的設置如下:

fyousuf$ rails -v
Rails 3.2.12

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

應用程序/資產/樣式表/ application.css

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

應用程序/資產/ JavaScript的/ application.js中

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

應用程序/資產/ 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});

應用程序/視圖/事件/ _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" }

在我的application.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_birth”,則會出現datepicker。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM