1

I'm using rails 4.1.6 under Ruby 2.1.3, if that's relevant. The gem I'm using is bootstrap-timepicker-rails from https://github.com/tispratik/bootstrap-timepicker-rails.

It's a new project, so I have added very little to it, other than basic functionality I use on every project. All I want is to be able to use timepicker like it's used in the first example of http://jdewit.github.io/bootstrap-timepicker/

So far, I have this in a partial view (from a table inside a form_for):

%tr
  %td=f.text_field :time, :class => 'timepicker'

And this on its js.coffee:

$(document).on 'focus', ".timepicker", ->
  $(this).timepicker()

And it behaves erratically. The fieldbox that contains the timepicker tries to show a time, but it locks at 12:00 am, and nothing else happens. I tried adding several other classes, including copying the source html code of the example I tried to use, but it doesn't work. No errors on the browser console either.

What am I missing?

Here're my relevant config files:

Gemfile:

gem 'haml-rails'
gem 'hirb'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'jquery-ui-rails'
gem 'autoprefixer-rails'
gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails', :git => 'git://github.com/Nerian/bootstrap-datepicker-rails.git'
gem 'bootstrap-timepicker-rails'
gem 'jquery-datatables-rails', '= 2.1.10.0.3'

application.js

//= require jquery
//= require jquery_ujs

//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require jquery-ui/core
//= require bootstrap-datepicker/core
//= require bootstrap-datepicker/locales/bootstrap-datepicker.es.js
//= require bootstrap-timepicker
//= require bootstrap-sprockets

//= require global

//= require turbolinks
//= require_tree .

application.css

*= require_tree .
*= require_self
*= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
*= require bootstrap-datepicker3
*= require bootstrap_files.css.scss
*= require bootstrap-timepicker

*= require global

Thanks in advance.

EDIT:

Apparently the issue is that I'm using bootstrap3 instead of boostrap2, which the gem I mentioned seems to be designed for. I'm going to search for a gem that can work with bootstrap3; I'll update when/if I find it.

dev404
  • 1,088
  • 13
  • 34
  • I would not use `on focus`. I would use [ready instead](http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links) and use `$('.timepicker').timepicker();` – mccannf Sep 30 '14 at 22:34
  • I have to use on focus, since the form is dynamic. The text_field can appear and vanish as I move other stuff in the form. With `ready` the javascript would not be loaded for the subsequent ones created via jQuery. – dev404 Sep 30 '14 at 22:37
  • ... and just to test it, it has the same effect I'm experiencing right now with `on focus`. – dev404 Sep 30 '14 at 22:43
  • 1
    Looks like others have had this issue: https://github.com/tispratik/bootstrap-timepicker-rails/issues/15 – mccannf Sep 30 '14 at 22:48
  • I just realized that the gem hasn't been touched in 2 years. Oh well. Guess I'll have to use something else. Thanks for pointing that out. – dev404 Sep 30 '14 at 23:01

0 Answers0