Skip to content

Instantly share code, notes, and snippets.

@voldy
Created January 7, 2010 17:15
Show Gist options
  • Save voldy/271377 to your computer and use it in GitHub Desktop.
Save voldy/271377 to your computer and use it in GitHub Desktop.
Using Formtastic and JQuery DatePicker
##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