Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-7184 Fixed showing incorrect value for DateTime and Time componen… #5393

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/datetime/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,15 @@ export default class DateTimeComponent extends Input {
format += format.match(/z$/) ? '' : ' z';
const timezone = this.timezone;
if (value && !this.attached && timezone) {
if (Array.isArray(value) && this.component.multiple) {
return value.map(item => _.trim(FormioUtils.momentDate(item, format, timezone).format(format))).join(', ');
}
return _.trim(FormioUtils.momentDate(value, format, timezone).format(format));
}

if (Array.isArray(value) && this.component.multiple) {
return value.map(item => _.trim(moment(item).format(format))).join(', ');
}
return (value ? _.trim(moment(value).format(format)) : value) || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if timezone is undefined and component is multiple? The line 207 is skipped and we go to line 211 that does not expect array value.
It also would be nice to separate repeated code in some new method. I mean lines 207 and 209. The same is for Time component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the repeated code should be separated in that case, because it is specific for that particular function.

}
}
3 changes: 3 additions & 0 deletions src/components/time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export default class TimeComponent extends TextFieldComponent {
}

getValueAsString(value) {
if (Array.isArray(value) && this.component.multiple) {
return value.map(item => moment(item, this.component.dataFormat).format(this.component.format)).join(', ');
}
return (value ? moment(value, this.component.dataFormat).format(this.component.format) : value) || '';
}

Expand Down
Loading