This is a simple gem for Active Admin that just adds support for Date/Time picker.
For Time picker widget, see just-time-picker.
Here comes a quick code sample. Sorry, currently no detailed docs.
That should create nice date/time picker for User#born_at. Associated column in the DB should be nullable.
To delete previously stored date/time just make all fields blank (date, hour and minute).
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.datetime :born_at t.timestamps end end end
class User < ActiveRecord::Base just_define_datetime_picker :born_at, :add_to_attr_accessible => true validates :born_at, :presence => true end
class User include Mongoid::Document field :born_at, type: DateTime just_define_datetime_picker :born_at, :add_to_attr_accessible => true end
You must place “mongoid” gem BEFORE “just-datetime-picker” gem in your Gemfile!
ActiveAdmin.register User do form do |f| f.inputs do f.input :born_at, :as => :just_datetime_picker end f.buttons end end
The gems are hosted at Rubygems.org. Make sure you're using the latest version of rubygems:
$ gem update --system
Then you can install the gem as follows:
$ gem install just-datetime-picker
Add to your Gemfile:
and then type:
The source code is available at github.com/saepia/just-datetime-picker. You can either clone the git repository or download a tarball or zip file. Once you have the source, you can unpack it and use from wherever you downloaded.
If you use Rails >= 3.1 AND ActiveAdmin >= 0.5.0 just add this line to active_admin.css.scss
Otherwise, just manually append the code from this file to your CSS stylesheet.
In ActiveAdmin 0.4.x you must strip body.active_admin from CSS declarations.
If you use nested set and dynamically create date or date/time pickers, they won’t be active by default due to bug in Active Admin.
To overcome that, if you use Rails >= 3.1 just add this line to active_admin.js
//= require just_datetime_picker/nested_form_workaround
Otherwise, just manually append the code from this file to your JS script.
Code was tested with:
ActiveAdmin 0.4.4, 0.5.0 and 0.5.1,
Ruby on Rails 3.2.8, 3.2.11.
This code is licensed under GPLv3.
Fixed nested form workaround - do not use obsolete jQuery live() syntax (Marcin Lewandowski)
Allow to set date time to null value (thanks to yaoquan for pointing this out)
Changed dependency of ActiveAdmin 0.5.0 to 0.4.4 (Marcin Lewandowski)
Fixed bug that caused “Invalid date” error if date field was empty which effectively made all date/time picker fields required, even if there were no associated validations (Marcin Lewandowski)
Added zh-CN locale (doabit)
Refactored CSS and JS to use total power of assets pipeline (Marcin Lewandowski)
Fixed bug that caused date/time fields' validations to always fail on record update if such field was not modified (Marcin Lewandowski)
Initial release (Marcin Lewandowski)