I'm having a case where we need a start and end date but we want the user to only be able to select some specific durations (in days like: 30 days, 90 days, 180 days, 360 days).

https://imgur.com/a/uSDMS2S

Apparently, there's no configuration way to remove the time fields (should be 00:00 in both) on start and end, except by checking "all day" but that also removes the "duration" select.

Essentially, smart dates assumes working with minutes/hours and not days/weeks/months which is kinda limiting the use of the module for no good reason?

Comments

Percept created an issue. See original summary.

Percept’s picture

Issue summary: View changes
Percept’s picture

Issue summary: View changes
Percept’s picture

Issue summary: View changes
mandclu’s picture

Rather than add complexity to the current widget, what if we made a separate widget specifically for handling date ranges?

Percept’s picture

That would be awesome, the module essentially does what I want, it's just an interface issue.

So what I'm looking for is a (smart) date field widget with:

  • start-date + and end-date (granularity day)
  • duration increaments select which changes the end-date to some preset relative values or custom (as it currently already does)

I just noticed I have 8.x-2.x installed and that 8.x-3.x works with core date fields which is probably required to get the granularity option?

mandclu’s picture

Since core datetime range fields natively support date only fields, it might make more sense to make a widget that's intended for those

jastraat’s picture

I'm also interested in this functionality. The core datetime range (date only) option doesn't support displaying just start date or just end date in views. Smart date does support this. So even though we need a widget with just date (no time), it's still better for us to use smart date.

In the interim, is there an easy way to make "all day" the default? It doesn't look like that checkbox is available in form alter, but perhaps I'm missing it.

jastraat’s picture

Version: 8.x-2.x-dev » 3.3.x-dev
mandclu’s picture

Smart Date doesn't actually store the "all day" value, so the checkbox is added via JS.

I'm inclined to think this would be best handled as a "date only" widget with its own JS, since it probably only needs a portion of the logic required for the other widgets.

You could set default increments that would correspond to day ranges with the current functionality, but it would be a little clunky, since Smart Date would be looking for those in minutes, and one minute shy of 1440 for the range. Theoretically it would be possible to switch the interpretation of the allowed increments when using a "date only" widget, but I could see this adding complexity to validation logic, etc.

jastraat’s picture

For our use case we don't really need the allowed increments; an additional "date range only" widget would be perfect. Essentially the existing widget without time, duration, or all day. I could see a widget like that also being useful for other use cases.

Should I create a separate feature request ticket?

mandclu’s picture

Thanks for the offer, but this issue is fine. One question: if a user has a date range defined (say, July 1-4) and then changes the start to be July 10, should it try to maintain the duration (in this case, 4 days) and update the end to July 13?

jastraat’s picture

I think that would be desirable but not necessary if it adds complexity.

I love the ability to change a start time and automatically have the end time update based on the duration. But it might be less important with date only.

As an update, I've tried to use both JS (checking the all day checkbox) in a custom library attached with form alter and alternatively setting the default values of start and end to '00:00:00' and '23:59:00' in a form alter as workarounds.

And they do work - but there's a flash of the time and duration widgets on page load which I think our client would find confusing.

mandclu’s picture

Status: Active » Needs review
StatusFileSize
new4.9 KB

Here's a first draft of a date only widget.

jastraat’s picture

Alrighty, tested the patch. The initial display of the widget is great - two date fields, no time or other clutter.

However, when trying to save a node with a smart date field that uses this new widget, I see the following error:

Notice: Undefined index: duration in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->massageFormValues() (line 285 of modules/composer/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php)

I tried replacing

unset($element['duration']);

in SmartDateOnlyWidget formElement() with

$element['duration']['#access'] = FALSE;

(Hiding instead of unsetting duration) And that seemed to address the issue.

Note: I think this would only work with a duration of 'custom' so that might need to be documented.

jastraat’s picture

Status: Needs review » Needs work
mandclu’s picture

Status: Needs work » Needs review
StatusFileSize
new4.91 KB

Thanks for the feedback. Here's a new patch with that change.

jastraat’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! The patch in #17 is working great for our use case. :)

  • eb6336e committed on 3.4.x
    Issue #3159828 by mandclu: Smart date assumes you need minutes/hours...
mandclu’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the quick feedback! Merged in, and hoping to get a new release rolled soon.

Status: Fixed » Closed (fixed)

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