Skip to content

Instantly share code, notes, and snippets.

@shanlalit
Forked from voldy/gist:271377
Created January 29, 2010 13:08
Show Gist options
  • Save shanlalit/289713 to your computer and use it in GitHub Desktop.
Save shanlalit/289713 to your computer and use it in GitHub Desktop.
##formtastic_datepicker_interface
module Formtastic
module DatePicker
protected
def datepicker_input(method, options = {})
format = options[:format] || ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] || '%d %b %Y'
string_input(method, datepicker_options(format, object.send(method)).merge(options))
end
# Generate html input options for the datepicker_input
#
def datepicker_options(format, value = nil)
datepicker_options = {:value => value.try(:strftime, format), :input_html => {:class => 'ui-datepicker'}}
end
end
end
##config/environment.rb
config.after_initialize do
require 'user_last_activity_updater'
Formtastic::SemanticFormBuilder.send(:include, Formtastic::DatePicker)
end
##application.js
$(document).ready(function(){
$('input.ui-datepicker').datepicker();
});
#usage in view file
= f.input :reminder_date, :as => :datepicker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment