Strict equality check in setInitialDuration causes end date/time fields to not hide

Created on 5 June 2024, 4 months ago
Updated 22 June 2024, 3 months ago

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

🐛 Bug report
Status

Fixed

Version

4.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024