Problem/Motivation

The base widget SmartDateWidgetBase establishes a min and max year for the date picker functionality. Currently there is no way to configure this through the UI.

Proposed resolution

- Add configuration to field widget to allow adjusting the min and max default attributes.

Workaround

Process the form element to override the defaults:

$element["field_myfield"]["widget"][0]["time_wrapper"]["value"]["#date_year_range"]
$element["field_myfield"]["widget"][0]["time_wrapper"]["end_value"]["#date_year_range"]

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#14 smart_date-3300768-14.patch967 bytesjrockowitz

Issue fork smart_date-3300768

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joewhitsitt created an issue. See original summary.

joewhitsitt’s picture

The min and max attributes are only set when the field has a value (e.g. default value)

docroot/core/lib/Drupal/Core/Datetime/Element/Datetime.php - processDatetime()

joewhitsitt’s picture

Issue summary: View changes
joewhitsitt’s picture

mandclu’s picture

Based on my own (admittedly limited) investigation, it seems as though we should be able to set #min and #max values, in addition to #date_year_range. Personally I'd prefer the two former (provided they actually work) as it sounds like they could provide more granular control, for example with a DrupalCamp restricting sessions to be scheduled during the days the camp actually runs.

  • mandclu committed 4aa93f7 on 3.6.x
    Issue #3300768 by mandclu: Widget configuration for min and max...
mandclu’s picture

Status: Active » Fixed

I ended up implementing this not as much in the widget configuration but in the field settings. Will open a child issues around adding a validation constraint so these can also be enforced when creating values programmatically, and also to make sure that these are respected for recurring values.

Will likely roll this into a beta release.

joewhitsitt’s picture

Thanks for this @mandclu. We will revisit our workaround when this is released.

mandclu’s picture

This has been included in the most recent release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joewhitsitt’s picture

@mandclu

I finally got a chance to look at this along with the schema commit and I am getting undefined array key min and max related to the "next hour" default functionality here if I leave the min and max blank like the help text says (not required).

https://git.drupalcode.org/project/smart_date/-/commit/4aa93f7#39ea69cdc...

When the min and max are set, instead of the next hour (today plus one hour), it defaults to the max limit (set as 2037-12-31) plus one hour. I think that is because of a typo

elseif ($limits['max'] && $date > $limits['min']) {

Should be:

elseif ($limits['max'] && $date > $limits['max']) {
mandclu’s picture

Status: Closed (fixed) » Needs work

Ah good catch. Did you test if it works as expected with that change?

joewhitsitt’s picture

I did in that very specific situation. Haven't had a moment to submit an MR and wasn't sure if it should be a separate issue

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new967 bytes

Here is a quick fix

joewhitsitt’s picture

Thanks @jrockowitz

I created an MR to cover both the if not empty check and the only if greater than max check.

mandclu’s picture

Version: 3.6.x-dev » 3.7.x-dev
Status: Needs review » Fixed

Thanks for everyone's work on this. The latest changes are merged into the 3.6.x and 3.7.x branches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.