Closed lesreaper closed 8 years ago
+1
It was a bit of a problem for me too. I wrote the following coffeescript hack to intercept form.submit, massage the date format, save it back to the input field value, and then allow the form to continue to submit as normal. Nothing to do on the rails side.
$('form').submit (event) ->
$(this).find('.datetime').each ->
$(this).val moment(new Date($(this).val()))
https://gist.github.com/IamNaN/e6cd2e9611c19f7933fc
Note, this example assumes that you are using moment.js and have added the datetime css class to the form's datetimepicker input fields. You need to change the class if you've used something else.
I recently switched my date format, I was asked to display them like "1er Juin 2015" (French), but then it isn't saving in the database anymore, and worse it has even corrupted all my entries that have been saved by POSTing this wrong date format =_=
I've seen that there are complicated fixes which involve making an additional hidden_field with the right value. Any chance we can get a nice helper to do that ?
Guys, could sby tell me which one I should use for this form issue: moment.js/american_date gem? Besides this what would you use for displaying the data: moment.js/local_time gem from basecamp? Notes: I don't want to ask users to submit their timezones. I would like to have a solution that figures out based on users' system. All of the parts of my app: server/db/rails are set to be UTC, so on user posting I want the users to be able to use local time which will be converted to UTC before saving it to db. When users try to edit the form the existing data from db should be displayed in local time.
I've changed the default view formats to match US (MM/DD/YYYY), but when the form that includes the datepicker is submitted, it does not map the month and days to the appropriate times in the database.
No one on Stack seems to have an answer that doesn't require significant customization of the gem, and there's no documentation really explaining how to set this up for US users.