Needs review
Project:
Single DateTimePicker
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2019 at 14:53 UTC
Updated:
6 Nov 2024 at 13:57 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tzandev commentedHere is the patch.
Comment #3
chrbak commentedOne way to change the above date format programatically is inside the HOOK_form_alter e.g.
Thank you for the patch.
Comment #4
blackiceuaAdded possibility to use custom format for the Date only element.
Fixed ES6 error issue.
Comment #6
valicI love the idea. Tnx on the initial patch. Committed in the dev version
The issue is on needs active still though I think would add this option to be configurable trough widget maybe.
Comment #7
edurenye commentedShouldn't it use '#format' instead of '#custom_format' as with date type?
Comment #8
ytsurkThanks for all your work.
Right now this is not supporting type datenone, and not applied to the initial values.
Comment #9
phjouI just made a patch for adding support in the field widget. It was pretty easy since the support for the form element has already been committed. I just changed one thing from the previous commit:
to
It was necessary since the default config is an empty string, the test needs to be empty and not just isset.
Let me know if it working, seems good on my local.
Comment #10
phjouActually I just noticed that using the new custom_format broke completely the save action.
Doing something like this using the current API without patch, (as in comment #3) will break completely your form when submitting
$form['my_field']['widget'][0]['value']['#custom_format'] = 'd/m/Y H:i';
It crashes that error:
Exception: DateTime object not set. in Drupal\Component\Datetime\DateTimePlus->__call() (line 355 of /app/web/core/lib/Drupal/Component/Datetime/DateTimePlus.php).Comment #11
phjouOk new patch containing the fix for the submission + @ytsurk comment about the default value.
Comment #12
ytsurkThx phjou!
Looks good. The format is now always initially set and I can confirm that saving work.
Don't remember what I meant with type datenone ..
Comment #13
jtriguero commentedIt doesn't work when you return from a failed validation to the form.
The problem is that the code returns in the valueCallback the date in format "Y-m-d \ TH: i: s".
Instead of trying to return the transformed value in the valueCallback, this should be done in the massageFormValues.
Attached patch and interdiff.
Comment #14
jtriguero commentedI forgot a "use".
Comment #15
spadxiii commentedRerolled against latest dev and added the default-value formatting for the timestamp widget.
Otherwise it seems to work just fine.
A feature I was thinking about was to be able to select a date-format as defined in the regional settings in drupal. (With the option of a blank text-field as 'Other').
Comment #16
linkl commentedFix the issue for date time range
Comment #17
spadxiii commentedAdded a small typo-fix:
$this-t()->$this->t()Comment #18
jcnventura@SpadXIII, can you please update the issue summary with what your patch fixes, please? The current issue summary should be kept intact at the bottom, as I believe it reflects the situation before the commit in #5.
Ideally, also post screenshots of the before and after of the change as I believe that now the custom form is part of the widget settings.
Once I understand what the post-#5 patches are trying to add, I'll test and merge.
Comment #19
spadxiii commented@jcnventura The commit in #5 only adds the option for the custom format so the javascript can handle a custom format.
The other patches add the option to configure it in the field widgets (through the field_ui interface)
Comment #20
jcnventuraOK. Good, I feel this would be a nice one to merge, but without it being RTBC, it may take some time.
Comment #21
spadxiii commentedFound a little bug with validating the value of a date range field. Fixed that in a new patch.
Also updated the private helper method for grabbing the date/time values.
Comment #22
spadxiii commentedFound another bug where it would still validate when leaving the end-date empty.
ps. an interdiff doesn't seem to generate :
interdiff: Whitespace damage detected in inputComment #23
spadxiii commentedFound another small issue where it would strip the time from the entered values. And the end-value wasn't handled correctly.
Here's a new patch.
Comment #24
idebr commentedThe new option to configure a custom format per field widget works as expected, thanks!
Comment #25
jcnventura@idebr, Thanks for the review. Why did you hide the patch from #23 and #16. Are you saying the one you tested is the last one not hidden (#14) ?
Please clarify and hide all files other than the one you tested, please..
Comment #26
idebr commentedI was unaware I changed the displayed patches. I tested the latest patch in #23.
Comment #28
idebr commentedAttached patch implements the following changes:
Comment #29
anneke_vde commentedI tested patch #28, looks good the default_value formatting is now correct.
Comment #30
chewi3 commentedRerolled the latest patch for 2.0.0-beta2.
Comment #31
watergate commentedI can confirm that this works correctly. Thanks for the patch.
Comment #32
shaxa commentedUnfortunately, patch number 30 doesn't work for me. There is one small mistake which causes on each save to delete the date from the fields. I have changed
$element['value']['#custom_format'] ?? $formatto$element['value']['#custom_format'] ?: $formatas the #custom_format is actually empty string by default.Comment #33
jcnventura