1

我想在我創建的窗體上使用Bootstrap Datepicker。我已閱讀了這裏的文檔:https://github.com/Nerian/bootstrap-datepicker-rails/issues/11並遵循它(或者我認爲),但我被卡住了。Bootstrap-Datepicker不能用Bootstrap-SASS顯示

Gemfile: 
gem 'bootstrap-sass', '2.0.4' 
gem 'bootstrap-datepicker-rails' 

應用程序/資產/ Javascript角/ application.js中

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

應用程序/資產/ Javascript角/ orders.js.coffee(I轉換的JavaScript來的CoffeeScript)

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

應用/stylesheets/application.css.scss

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

形式(相關部分,反正):

<%= form_for [@user, @order] do |order_form| %> 

    <%= order_form.label "When would you like us to pick up your stuff?" %> 
    <%= order_form.text_field :order_date, placeholder: "yyyy-mm-dd", 'data-behaviour' => 'datepicker' %> 

<% end %> 

當我進入控制檯,我可以調用元素的日期選擇器()方法,並從那裏操縱其屬性。但是,無論出於何種原因,在頁面加載時它都不起作用。並且在控制檯中沒有任何錯誤。

(基於我在這裏讀到的:Twitter bootstrap datepicker is not working in rails,我嘗試了require_self的東西,並將javascript放在application.js文件中,它沒有工作,我不喜歡在JavaScript中使用JavaScript的想法application.js文件無論如何...)

回答

2

我沒有成功整合Twitter Bootstrap Datepicker與我的應用程序。相反,我使用標準jQuery datepicker並選擇與我的應用程序相匹配的主題。我的代碼最終看上去像這樣:

形式:

<%= order_form.label "When would you like us to pick up your stuff?" %> 
<%= order_form.text_field :order_date, id:"datepicker" %> 

的CoffeeScript的:

$ -> 
    $("#datepicker").datepicker({ 
    minDate: +1, 
    dateFormat:"yy-mm-dd" 
    }) 

我加入這行到我的custom.css文件的頂部(前@import bootstrap line)

@import url(http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/smoothness/jquery-ui.css); 

in application.css.scss(notice I removed require_bootstrap-datepick呃)

*= require_self 
*= require_tree . 
*/ 

我從我的寶石文件中刪除了寶石。

我不知道Twitter Bootstrap datepicker會看起來有多不同,但是這個主題對我的應用程序來說非常合適。

+0

有同樣的問題,似乎無法解決它。 html肯定是點擊生成的,但是它的樣式似乎是關閉的。 –