Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I've got a custom content type with a date field using the popup widget. I've added a custom format (d F Y h:ia) under admin/config/regional/date-time/formats but when I go to the field, under the drop down "CHOOSE HOW USERS ENTER DATES" that format isn't available. I noticed the system module provides this functionality to add the custom formats but I assume that I should be able to use them in input formats? I'm using the lastest dev version as of today.
Comment | File | Size | Author |
---|---|---|---|
#34 | date_popup_1246940.patch | 808 bytes | andreyks |
Comments
Comment #1
arlinsandbulte CreditAttribution: arlinsandbulte commentedSounds like you added a custom format at /admin/config/regional/date-time/formats
BUT
Did you also add a date type at /admin/config/regional/date-time??
You must first create a custom format, then use that format in a new date type.
Comment #2
acbramley CreditAttribution: acbramley commentedYup, in fact I've got 2 custom date types, one using that format and another using just d F Y but still no luck. I've cleared all caches etc as well.
Comment #3
arlinsandbulte CreditAttribution: arlinsandbulte commentedAh, OK. I follow now.
Hmmm... I don't think input formats CAN be customized... I was not aware of this limitation... was this different in older versions of date?
I just tried in D6 version too and this issue is there too. Only 14 different (hard coded?) input formats are allowed, even though there are 35 available default formats that can be selected when creating a new type. It looks like only output/display formats can be customized.
But I could be wrong,
@KarenS: can you confirm that this is a feature request?
Comment #4
acbramley CreditAttribution: acbramley commentedHmmmm, I was sure you could do it in D6 but maybe I'm wrong. It would be a great feature!
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedFor input formats, you can't reuse the ones defined at admin/config/regional/date-time/formats, but you can add a custom format by choosing the "Custom input format" option in the "Choose how users enter dates" dropdown and then typing your own in there.
Or at least, you can do that for select widgets and textfield widgets. For popup widgets, the code in _date_field_widget_settings_form() specifically hides the ability to use a custom format, so I think that's why it's not showing up in the above example.
I'm not sure what the exact rationale for that is, but my guess would be that since the popup code separates date and time into two separate input fields, it needs to be able to take whatever format you give it and parse it to figure out how to split apart the date and time. Maybe the idea is that it's not possible to guarantee that splitting will work correctly for an arbitrary format string.
Comment #6
acbramley CreditAttribution: acbramley commentedYeah that makes sense. It would be nice if there was a few more available options like full month names etc.
Comment #7
KarenS CreditAttribution: KarenS commentedThe reason for hiding custom formats with the popup date picker is because it won't handle anything you might come up with. See http://jqueryui.com/demos/datepicker/#date-formats, the examples are pretty limited. I haven't figured out exactly which would work and which wouldn't, but you definitely can't use everything that you can use everywhere else.
I suppose we could enable the custom format for the popup with some sort of warning text that not all formats will work.
Comment #8
KarenS CreditAttribution: KarenS commentedAlso it does not use the same formats that the PHP date format uses, see http://docs.jquery.com/UI/Datepicker/formatDate. So you have to pick a format it supports and then massage it into the values that the datepicker wants.
So the current code has options that are known to work and no custom format. Any attempt to change it would require figuring out how to manipulate custom code into something that the datepicker likes.
Comment #9
KarenS CreditAttribution: KarenS commentedRe-naming this issue. This is just about the Date Popup widget, right?
Comment #10
KarenS CreditAttribution: KarenS commentedHmm, just took care of #1241254: "Date format is invalid" error when using Popup calendar widget which illustrates that you can still get non-functional formats into the popup. Just add whatever you want as your 'short', 'medium', or 'long' format and it will be available, but that doesn't guarantee that it will work.
The old code had a specific list of formats that would work right for the popup field. Not sure if that got 'fixed' in the lastest round of changes.
Since there is in fact a way to try to use this with any format you might dream up, we might as well re-enable the 'custom' option with the warning that not all formats will work right in the popup.
Comment #11
acbramley CreditAttribution: acbramley commentedAgree with KarenS.
Comment #12
yingtho CreditAttribution: yingtho commentedHere is a patch to include custom dateformat against version 2.6.
Comment #14
yingtho CreditAttribution: yingtho commentedThis time it a proper git diff patch.
Comment #15
yingtho CreditAttribution: yingtho commentedThis is testede and working patch. Done via clone of date module.
Comment #16
yingtho CreditAttribution: yingtho commentedChange status so it will be testede again.
Comment #18
yingtho CreditAttribution: yingtho commented#15: date_popup-add-custom-formats.patch queued for re-testing.
Comment #20
yingtho CreditAttribution: yingtho commentedRemove warning messages.
Comment #21
yingtho CreditAttribution: yingtho commentedRetest.
Comment #23
yingtho CreditAttribution: yingtho commentedWe try again.
Comment #24
yingtho CreditAttribution: yingtho commentedWrong file. We try again.
Comment #25
yingtho CreditAttribution: yingtho commentedOr this one.
Comment #27
yingtho CreditAttribution: yingtho commentedThe test failed due to "Class 'Migration' not found" but i haven't made any changes to this so it seems the normal test will also fail.
Comment #28
sisko CreditAttribution: sisko commentedSuggestion:
Save your date as a timestamp. You can still use the Date-popup but when you output the date via Views or example, you can output in the desired format.
Comment #29
zwerg CreditAttribution: zwerg commentedIs there any solution?
Comment #32
andreyks CreditAttribution: andreyks commentedComment #33
sanchiz CreditAttribution: sanchiz commentedComment #34
andreyks CreditAttribution: andreyks commentedUpdate #25
Comment #35
sanchiz CreditAttribution: sanchiz commentedbot trigger
Comment #36
podarok#34 commited.
Thanks!
Comment #39
GrantI CreditAttribution: GrantI commented#34 worked perfectly for me!
NOTE OF CAUTION
If you are collecting a time along with your date make sure that your custom format also includes php time values for each unit (hour, minute and second) or you will break your input, as the time option won't display.
I went for the following format;
Tue 7 Jul - 07:29:53pm
PHP;
D j M - h:i:sa
Hope this helps.