简体   繁体   中英

how to add date picker in activescaffold with rails4

At https://github.com/activescaffold/active_scaffold/wiki/API:-Column

It recommends to install a plugin: https://github.com/scambra/unobtrusive_date_picker

Now I am using rails4 so can't really install a plugin as it says rails 4 has removed support for plugins at: http://blog.remarkablelabs.com/2012/12/rails-plugin-reaches-end-of-life-rails-4-countdown-to-2013

Please suggest how I can turn all the date fields to data pickers in activescaffold. Simpler the better.

Thanks

EDIT: Adding response to a comment:

Loading development environment (Rails 4.1.4)
2.1.1 :001 > ActiveScaffold.exclude_bridges.exclude? :date_picker
 => true 
2.1.1 :002 > ActiveScaffold::Bridges::DatePicker.install?
 => true 
2.1.1 :003 > ActiveScaffold::Bridges::DatePicker.jquery_ui_included?
 => true 
2.1.1 :004 > Jquery.const_defined?('Ui')
 => false 
2.1.1 :005 > 
2.1.1 :007 > Admin::PlansController.active_scaffold_config.columns[:plan_start].form_ui
 => :date_picker 

Date Picker Bridge is now in active scaffold core. Active Scaffold will automatically detect that Date Picker is installed, and will make use it.

You just need to include jQuery and jQueryUI as dependencies. It can be added via jquery-ui-rails gem is on your gemset, activescaffold will load it.

You can check it from console:

Jquery.const_defined?('Ui')
ActiveScaffold::Bridges::DatePicker.jquery_ui_included?
ActiveScaffold::Bridges::DatePicker.install?
ActiveScaffold.exclude_bridges.exclude? :date_picker

YourController.active_scaffold_config.columns[:date_column].form_ui

Just change controller and column name to check form ui element for desired column, it should be :date_picker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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