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
- Go to https://simplytest.me/
- Select "Smart Date Starter Kit"
- Edit the Smart Date field at "admin/structure/types/manage/event/fields/node.event.field_when"
- Add `0|Ongoing` to allowed duration values
- Set default duration to `0`
- Add a new event "/node/add/event" and notice that `time-end` is visible
- Change duration from "Ongoing" to "30 minutes" and then switch back to "Ongoing"
- 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
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
Comment #2
bspeare commentedComment #3
bspeare commentedComment #4
bspeare commentedComment #7
mandclu commentedYour suggested changes (expanded a little) work on my local ¯\_(ツ)_/¯
Comment #8
bspeare commentedThank you @mandclu!
Comment #9
bspeare commentedComment #10
bspeare commentedComment #12
mandclu commentedThanks for the feedback! Merged in.