DatetimePickerInput
DatetimePickerInput allows you to easily add a JavaScript datetime picker to your Ruby on Rails, Bootstrap-enabled Simple Form input.
Prerequisites
Rails 3.1 and 4+ compatible, and your app should already have Bootstrap and Simple Form installed.
Otherwise, set up Bootstrap and Simple Form now.
Installation
Add this to your application's Gemfile then run bundle install
:
gem 'datetime_picker_input'
In the JavaScript manifest file application.js
, add:
//= require datetime_picker_input
In the CSS manifest file application.scss
, add:
@import 'datetime_picker_input';
or application.css
:
*= require datetime_picker_input
Usage
Demo app is available at http://datetime-picker-input.herokuapp.com.
Simple Usage
= simple_form_for Event.new do |f|
f.input :when, as: :date_time_picker
Customized Options
= f.input :when, as: :date_time_picker, input_html:
{ data:
{
date_format: "YYYY-MM-DD hh:mm A",
date_day_view_header_format: 'MMM YYYY',
date_side_by_side: true,
date_min_date: Time.current.strftime('%Y-%m-%d')
}
}
Bootstrap 3 Datepicker is able to initialize a datetime picker through the use of data
attributes on the input
field.
To do that, modify any of the options specified in Bootstrap 3 Datepicker's Doc by adding a prefix of date
and underscoring the resulting option name.
For example:
dayViewHeaderFormat
todate_day_view_header_format
minDate
todate_min_date
Customization
To customize the input field, you can copy datetime_picker_input.rb
from the gem to your app by using the generator included in datetime_picker_input
.
Simple do:
$ rails g datetime_picker_input:install
This will generate datetime_picker_input.rb
under app/inputs
directory which you can modify.
Dependencies
This gem is heavily dependent on and only possible because of the great work done in these gems:
- https://github.com/TrevorS/bootstrap3-datetimepicker-rails
- https://github.com/derekprior/momentjs-rails
Versioning
Since this gem is ultimately dependent on https://github.com/Eonasdan/bootstrap-datetimepicker, this gem shall have the same version as the JavaScript plugin - current release version is 4.0.0.
Any bug fix release of this gem will have a 4th decimal added, e.g. 4.0.0.1, 4.0.0.2.
Contributing
- Fork it ( https://github.com/jollygoodcode/datetime_picker_input/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Credits
A huge THANK YOU to all our contributors! :heart:
This project is maintained by Jolly Good Code.
License
MIT License. See LICENSE for details.