jquery_datepicker icon indicating copy to clipboard operation
jquery_datepicker copied to clipboard

Time Format when editing

Open webbtj opened this issue 11 years ago • 1 comments

Sorry, this is more of a support issue than a bug (though maybe it's a bug with the docs?).

I have a datetime_picker field working perfectly for creating. I get the format I want with no issues. What I'm struggling with is editing that same model. When editing a model with the datetime_picker field it's populating the field with a different format specifically, it is including seconds and milliseconds (which I'm going to assume is the default date format in Rails -- still kinda new and haven't changed that on this project). Once I click the field to edit it and pick a new date/time it again displays the date in the format I have chosen, I just don't want my users to see this seconds/milliseconds display. Any suggestions?

In my edit view: <%= f.datetime_picker :starts_at, :stepMinute => 15, :dateFormat => "yy-mm-dd", placeholder: "Start Date & Time" %>

webbtj avatar Jun 25 '13 14:06 webbtj

Hi! The problem is that when editing, Rails is setting initial value of the input (using the default format in your app). You have 2 options:

1.- Change the default format, creating a date_format.rb (for example) file in config/initalizers and add these two lines (changing the format as you wish, obviously):

Time::DATE_FORMATS[:default] = '%m/%d/%Y %H:%M:%S'
Date::DATE_FORMATS[:default] = '%m/%d/%Y'

2.- Re-format the value that is going to be set in your controller (or view), after retrieving it from the DB.

Hope this helps!

albertopq avatar Jun 26 '13 10:06 albertopq