Problem/Motivation

Currently, there is no way to prevent the datepicker from setting a default value. Even if you set an empty field value, the widget will use the current time.

Proposed resolution

There are settings available which allow for disabling of the initTime and defaultValues. We could add them as a setting.

Remaining tasks

Write patch. Review. Test. Commit.

User interface changes

An additional checkbox for disabling default values. This ensures backward compatibility.

API changes

We add 2 data attributes: initTime and defaultSelect.

Data model changes

None.

Release notes snippet

An new form display setting "Disable default value". When checked, no default values will be used in the datepicker.

CommentFileSizeAuthor
#2 3048285-2.patch4.28 KBaskibinski

Comments

askibinski created an issue. See original summary.

askibinski’s picture

Status: Active » Needs review
StatusFileSize
new4.28 KB
lendude’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/src/Plugin/Field/FieldWidget/SingleDateTimeBase.php
@@ -237,6 +245,8 @@ abstract class SingleDateTimeBase extends DateTimeWidgetBase implements Containe
+    $summary[] = t('Disable default: @disable_default', ['@disable_default' => !empty($this->getSetting('disable_default')) ? t('Yes') : t('No')]);

This should use $this->t() too, but since half that method uses it and half of it doesn't *shrug*

Manually tested this with date fields and date range fields and works as specified.

askibinski’s picture

Status: Reviewed & tested by the community » Needs work

I think this would need to be split up further and needs more investigation because with above patch you also need to unset the default value in the Drupal field. However, it might be that the problem is in the JS library as the 2 options mentioned above do not work as expected.