Closed (fixed)
Project:
Smart Date
Version:
3.3.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Jul 2020 at 11:12 UTC
Updated:
18 Jun 2021 at 20:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
Percept commentedComment #3
Percept commentedComment #4
Percept commentedComment #5
mandclu commentedRather than add complexity to the current widget, what if we made a separate widget specifically for handling date ranges?
Comment #6
Percept commentedThat 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:
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?
Comment #7
mandclu commentedSince core datetime range fields natively support date only fields, it might make more sense to make a widget that's intended for those
Comment #8
jastraat commentedI'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.
Comment #9
jastraat commentedComment #10
mandclu commentedSmart 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.
Comment #11
jastraat commentedFor 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?
Comment #12
mandclu commentedThanks 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?
Comment #13
jastraat commentedI 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.
Comment #14
mandclu commentedHere's a first draft of a date only widget.
Comment #15
jastraat commentedAlrighty, 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.
Comment #16
jastraat commentedComment #17
mandclu commentedThanks for the feedback. Here's a new patch with that change.
Comment #18
jastraat commentedThanks! The patch in #17 is working great for our use case. :)
Comment #20
mandclu commentedThanks for the quick feedback! Merged in, and hoping to get a new release rolled soon.