Closed (duplicate)
Project:
Drupal core
Version:
9.3.x-dev
Component:
datetime.module
Priority:
Major
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Jan 2016 at 04:27 UTC
Updated:
13 Oct 2021 at 15:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
no sssweat commentedComment #3
no sssweat commentedComment #4
mpdonadioNot sure how this applies since it is an element, so it should be localized by your browser? Or are you on a browser like Firefox that uses the polyfill?
Comment #5
no sssweat commented@mpdonadio You're right about the browser. In Chrome I cannot paste anything to there and brings up a Calendar widget, but with Firefox I can paste and there is no Calendar widget (which is nice IMO).
But... it would still be nice if we could custom format it.
Ex:
When editing or creating a node in D8 my date field is always stuck to this format http://i.stack.imgur.com/34pjR.jpg
Side note: I think I just discovered a bug, when mouse hover over it, it's giving an incorrect example. Year should be last... http://i.stack.imgur.com/34pjR.jpg
While in D7 I can customize it http://i.stack.imgur.com/HogyD.jpg and http://i.stack.imgur.com/Aa1jz.jpg. I can format it however I want using the date function http://php.net/manual/en/function.date.php. I could put
M d, YSo I have the freedom to make that people have to type Feb 25, 2016 instead of 02/25/2016Comment #6
no sssweat commentedEdited comment #5, just bumping this, so you get the notification, just in case you saw my original version.
Comment #7
swentel commentedYeah, the HTML5 datefield isn't always great, or even user friendly in terms of format. Maybe we should allow selecting the html type ?
Comment #9
webel commented@Camster I agree, also want to be able to easily change the format for editing dates as one could in D7.
For example, the Drupal project/module page release dates sensibly use ordering-friendly YYYY-MM-DD, but the edit form for Date in Drupal8 seems to be fixed at dd/mm/yyy using a widget.
Comment #10
mpdonadioThese are input type=date elements, which don't have format specifiers per the spec.
I fear allowing users to specify the HTML type for these will get us closer to the do-it-all road.
I am leading towards keeping these the way they are in core, and having this be something the contrib space can handle, since it would just be swapping out the form widgets.
?
Comment #13
kclarkson commentedwould also like to see this! There are so many different reasons why you may need to change the date format within the form.
This is a huge user experience improvement that would be helpful out of the box.
Comment #14
leisurman commentedCan the default date format Y/m/d be changed to m/d/Y in the edit form with a hook alter and what hook can be used?
Comment #15
mpdonadio#14, yes and no. The widgets use the Datetime form element, which by default uses the HTML5 input elements. Those require the HTML5 date and time formats (Y-m-d and H:i:s). If you want a different format, you need make a new widget and change the types to text so you can specify your own format (but you lose the popups), or you can do this via a form_alter. Off the top of my head, I am not positive which form_id to target with the form_alter.
Comment #16
leisurman commentedIn case anyone needs this
Comment #17
rodrigoaguilera@leisurman that code works fine for the ui part but date fields have validators that expect the HTML5 format on the backend.
I think we should do something similar to what is explained on this thread
http://stackoverflow.com/questions/27850791/input-type-date-format-and-d...
But I feel it should go into contrib with a new field formatter with its own config.
I don't know how can we have a interface to change the the date format of other widgets like the published date but that can probably can be handled in the contrib module.
Comment #19
shaktikComment #21
imclean commentedHere's a nice example of things simply not working. Using Drupal 8.4.x. and the core media module, I've added a standard "Date" field to a media entity. In Chrome, the field expects the input to be mm/dd/yyyy, which makes sense in my part of the world.
The field itself expects YYYY-MM-DD, which I wouldn't mind either. However, neither of these are configurable that I can see, resulting in an error.
Comment #22
imclean commentedNever mind, the date format wasn't the problem in my case, I needed to enter a time. It submitted fine in the specified format. I'd like to make the time optional but that's another issue.
Comment #23
imclean commentedComment #24
imclean commentedSee also: #2791693: Remove sample date from date field error message and title attribute
Comment #25
andrezstar commented#16 worked for me but then the form validation wont accept this format for InternetExplorer.
It does validate for other browsers tho...
Weird, isnt it?
Comment #30
dunebl#16 is no more working on D8.9.1
As an example for why this is not working, the key
$element['date']['#attributes']['data-drupal-date-format']used in the #16 code doesn't exists anymore.I changed the priority into Major, because There is no way to change the format of the date widget.
Use case: European peoples working on English system/browser (which is very common) => they need a
d/m/Ywidget.The only way I could solve this issue is to use the select list plugin
Comment #31
tawellman commentedI am running into a similar problem.
I have a use case where the user needs to be able to copy the date from another source and paste that value into the date field. It would be too time-consuming to have to pick the date from a "date picker" widget. It would be ok if it were a one-off situation but this user needs to be able to enter several at a time.
I agree that it would be extreemly helpful if a "Text Field" Widget was available again.
Comment #32
no sssweat commentedThere are now contrib modules that will allow you to change it, see https://drupal.stackexchange.com/a/297000/27710
Comment #35
quietone commentedDiscovered this while looking for duplicates, tagging Bug Smash Initiative.
There is a later issue, with more discussion and patch, for this problem. Although this is the earliest I have found closing this as a duplicate.
Comment #36
quietone commentedComment #37
franxo commentedHi all,
Just to comment on the workaround I have used to solve this, in case it helps someone.
Contrib module: Datetime Flatpickr (https://www.drupal.org/project/datetime_flatpickr)
Configuration for the Flatpickr datetime picker:
Alternative input format: d/m/Y
Date format: Y-m-d
Regards,