简体   繁体   English

bootstrap-datepicker-rails无法通过带引导模式的simple_form工作

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

I'm trying to get a datepicker (using bootstrap-datepicker-rails gem ) to display via simple_form with bootstrap modal , but having no luck. 我试图通过带引导模式的 simple_form显示一个datepicker (使用bootstrap-datepicker-rails gem ),但没有运气。

I've read a bunch of stuff such as: 我读了很多东西,比如:

https://github.com/Nerian/bootstrap-datepicker-rails/issues/51 How to setup bootstrap-datepicker-rails? 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-easy-way http://learningnewtricks.wordpress.com/2013/07/03/bootstrap-date-picker-on-rails-so-simple/ http://www.chadcf.com/blog/jqueryui-datepicker-rails-and- simpleform易路

All I get is a textfield but when I click on it there is no datepicker. 我得到的只是一个文本字段,但当我点击它时,没有日期选择器。 Could it be the datepicker is behind the modal, if so how to fix that? 可能是日期选择器背后的模态,如果是这样如何解决?

My setup is as follows: 我的设置如下:

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 应用程序/资产/样式表/ application.css

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

app/assets/javascripts/application.js 应用程序/资产/ JavaScript的/ 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 应用程序/资产/ 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 应用程序/视图/事件/ _form.html.erb

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

On my view 在我看来

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

On my application.js 在我的application.js上

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

The versions that I'm using 我正在使用的版本

> bundle | grep bootstrap

Using bootstrap-datepicker-rails 1.3.0.2
Using twitter-bootstrap-rails 2.2.8

It's perfectly working for me. 它对我来说非常合适。 Right after the form is loaded if I click on the input "date_of_birth" the datepicker appears. 在加载表单后,如果单击输入“date_of_birth”,则会出现datepicker。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM