README.md in xdan-datetimepicker-rails-2.3.9 vs README.md in xdan-datetimepicker-rails-2.4.1

- old
+ new

@@ -31,14 +31,105 @@ ``` Start using it! ```coffee +# /app/assets/javascripts/datetimepicker.js.coffee + +#= require jquery.xdan.datetimepicker + +@setupDateTimePicker = (container) -> + defaults = { + formatDate: 'y-m-d', + format: 'Y-m-d H:i', + allowBlank: true, + defaultSelect: false, + validateOnBlur: false + } + + entries = $(container).find('input.datetimepicker') + entries.each (index, entry) -> + options = $(entry).data 'datepicker-options' + $(entry).datetimepicker $.extend(defaults, options) + $ -> - $(".datetimepicker").datetimepicker() + setupDateTimePicker $('body') + ``` + See the [detailed documentation](http://xdsoft.net/jqplugins/datetimepicker/) for more options. When the site is back up I'll try to port some of them into this README or move them to the official repo of [datetimepicker](https://github.com/xdan/datetimepicker). + +### SimpleForm Integration + +```ruby +# /app/inputs/datetimepicker_input.rb + +class DatetimepickerInput < SimpleForm::Inputs::StringInput + def input_html_classes + super.push("datetimepicker") + end + + def input_type + :string + end + + def input_html_options + super.tap do |opts| + opts[:data] ||= {} + opts[:data].merge! datepicker_options + opts[:value] ||= value + end + end + + def value + val = object.send(attribute_name) + return DateTime.new(val.year, val.month, val.day, val.hour, val.min).strftime("%Y-%m-%d %H:%M") if val.is_a?(Time) + return val if val.nil? + val.to_s + end + + private + def datepicker_options + options = self.options.fetch(:datepicker_options, {}) + options = Hash[options.map{ |k, v| [k.to_s.camelcase(:lower), v] }] + { datepicker_options: options } + end +end + +``` + +### Formtastic Integration + +```ruby +# /app/inputs/datetimepicker_input.rb + +class DatetimepickerInput < ::Formtastic::Inputs::StringInput + def input_html_options + super.tap do |options| + options[:class] = [options[:class], "datetimepicker"].compact.join(' ') + options[:data] ||= {} + options[:data].merge! datepicker_options + options[:value] ||= value + end + end + + def value + val = object.send(method) + return DateTime.new(val.year, val.month, val.day, val.hour, val.min).strftime("%Y-%m-%d %H:%M") if val.is_a?(Time) + return val if val.nil? + val.to_s + end + + private + def datepicker_options + options = self.options.fetch(:datepicker_options, {}) + options = Hash[options.map{ |k, v| [k.to_s.camelcase(:lower), v] }] + { datepicker_options: options } + end +end + +``` ## Versioning This gem will attempt to maintain the same version as the `datetimepicker` library.