albertopq / jquery_datepicker

Rails 3 plugin that allows you to select dates from a calendar
91 stars 60 forks source link

Add example on how to format the time part of datetime_picker #23

Closed donv closed 9 years ago

testflyjets commented 12 years ago

It would be very handy to have an example of this. The statement in the README regarding this is a bit confusing:

Important! Be aware the way Rails stores the datetime fields cause you’ll need to specify the dateFormat to “yy-mm-dd” or pre-process your field value on the controller. The default format won’t work.

Can you explain how an existing date can be formatted so it appears in the datepicker input, for example, as "June 26, 2012"?

albertopq commented 11 years ago

I know is late for an answer, but might be useful for others. The default date format in Rails and how they are appearing in the input should match in order to make it work when saving the field. To define the default date format in your Rails app, add an initialiser into config/ with: Date::DATE_FORMATS[:default] = "%m-%d-%Y" Time::DATE_FORMATS[:default] = "%m-%d-%Y %H:%M"

Then, you should use the datepicker options to set them in the same way, using the dateFormat parameter:

http://api.jqueryui.com/datepicker/#option-dateFormat

So, answering your question, use the options in the link bellow for setting the format as you wish.

I'll add clarifications into the README file. Thanks!

donv commented 9 years ago

We have stopped using this gem, so this issue is obsolete.