Problem/Motivation

Hello, we are updating from 4.0.3 and noticing that there might be a bug with 4.1.3 in the `setInitialDuration` function where the strict equality operator (`===`) is used when comparing the `duration` variable to the value `0`.

Steps to reproduce

  1. Go to https://simplytest.me/
  2. Select "Smart Date Starter Kit"
  3. Edit the Smart Date field at "admin/structure/types/manage/event/fields/node.event.field_when"
  4. Add `0|Ongoing` to allowed duration values
  5. Set default duration to `0`
  6. Add a new event "/node/add/event" and notice that `time-end` is visible
  7. Change duration from "Ongoing" to "30 minutes" and then switch back to "Ongoing"
  8. Notice that `time-end` is hidden only after making the switch and not on the initial page load.

Expected Behavior
The end date and time fields should be hidden when the "Ongoing" option is selected on page load.

Proposed resolution

In 4.0.3 the code worked when the equality operator was `if (duration == 0)`, however the`setInitialDuration` function in 4.1.3 has the condition `if (duration === 0)` is now strict and doesn't seem to work with 0.

To fix this issue, should we convert the duration value to a number before comparing it to 0?

if (+duration === 0) {
  // Call this to hide the end date and time.
  durationChanged(element);
}

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork smart_date-3452796

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

bspeare created an issue. See original summary.

bspeare’s picture

Issue summary: View changes
bspeare’s picture

Issue summary: View changes
bspeare’s picture

Issue summary: View changes

mandclu made their first commit to this issue’s fork.

mandclu’s picture

Status: Active » Needs review

Your suggested changes (expanded a little) work on my local ¯\_(ツ)_/¯

bspeare’s picture

Status: Needs review » Active

Thank you @mandclu!

bspeare’s picture

Status: Active » Needs review
bspeare’s picture

Status: Needs review » Reviewed & tested by the community

  • mandclu committed e08e8c9d on 4.1.x
    Issue #3452796 by mandclu: Strict equality check in setInitialDuration...
mandclu’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the feedback! Merged in.

Status: Fixed » Closed (fixed)

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