-
-
Save shanlalit/289713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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