如何设置 bootstrap-datepicker-rails? [英] How to setup bootstrap-datepicker-rails?

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

问题描述

有人知道如何设置 gem bootstrap-datepicker-rails 吗?我按照 http://rubydoc.info/gems/bootstrap-datepicker-rails/0.6.21/frames,基本上:

  1. 我设置了 twitter-bootstrap-rails gem
  2. 我将此添加到 gemfile gem 'bootstrap-datepicker-rails', '>= 0.6.21'
  3. 将此行添加到 app/assets/stylesheets/application.css

    *= 需要 bootstrap-datepicker

  4. 将此行添加到 app/assets/javascripts/application.js

    //= 需要 bootstrap-datepicker

  5. 将此行添加到 app/assets/javascripts/controllername.js.coffee

    $('.datepicker').datepicker()

  6. 最后在视图中使用:)

但是没有用!!有人让它工作吗?它应该很好用,如下所示:
http://jsfiddle.net/2Gg5k/43/

解决方案

看第 5 步和第 6 步,你的选择类 .datepicker 在 javascript 但不在 input field>

试试这个

关于视图(例如表单)

<%= f.text_field :mydate, 'data-behaviour' =>'日期选择器'%><script type="text/javascript">$('[数据行为~=datepicker]').datepicker();

或作为组件:

<%= f.text_field :mydate, 'data-behaviour' =>'datepicker', :disabled =>'禁用'%><span class="add-on"><i class="icon-th"></i></span>

<script type="text/javascript">$('.datepicker').datepicker();

以上示例,如果属性使用 date 类型.您可以使用 bootstrap-datetimepicker-rails gem,如果使用 datetime 的属性 输入

Anybody knows how to setup the gem bootstrap-datepicker-rails? I followed the steps in http://rubydoc.info/gems/bootstrap-datepicker-rails/0.6.21/frames, basically:

  1. I setup twitter-bootstrap-rails gem
  2. I add this to gemfile gem 'bootstrap-datepicker-rails', '>= 0.6.21'
  3. Add this line to app/assets/stylesheets/application.css

    *= require bootstrap-datepicker
    

  4. Add this line to app/assets/javascripts/application.js

    //= require bootstrap-datepicker
    

  5. Add this line to app/assets/javascripts/controllername.js.coffee

    $('.datepicker').datepicker()
    

  6. Finally use in view :)

    <input type="text" data-behaviour='datepicker' >
    

But it doesn't work!! Anybody has got it to work? It should work nice as shown here:
http://jsfiddle.net/2Gg5k/43/

解决方案

Look at step 5 and step 6, your selection class .datepicker in javascript but not in input field

Try this

on views (e.g form)

<%= f.text_field :mydate, 'data-behaviour' => 'datepicker' %>

<script type="text/javascript">
  $('[data-behaviour~=datepicker]').datepicker();
</script>

Or As component :

<div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
    <%= f.text_field :mydate, 'data-behaviour' => 'datepicker', :disabled => 'disable' %><span class="add-on"><i class="icon-th"></i></span>
</div>

<script type="text/javascript">
  $('.datepicker').datepicker();
</script>

Example above all if the attribute using date type. You can use bootstrap-datetimepicker-rails gem, if the attribute using datetime type

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

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