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

BACKLOG-23452: Trim the date format when configured #1786

Merged
merged 1 commit into from
Jan 10, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getDateFormat(editorContext) {
const allowedOverridesDateFormat = ['MM/DD/YYYY', 'DD/MM/YYYY'];

// Read date format from config
const forceDateFormat = window.contextJsParameters?.config?.contentEditor?.forceDateFormat;
const forceDateFormat = window.contextJsParameters?.config?.contentEditor?.forceDateFormat?.trim();
if (forceDateFormat && !allowedOverridesDateFormat.includes(forceDateFormat)) {
console.warn(`forceDateFormat as been set to an invalid value (${forceDateFormat}). Please use one of the following values: ${allowedOverridesDateFormat.join(', ')}`);
} else if (forceDateFormat) {
Expand Down
11 changes: 11 additions & 0 deletions src/javascript/SelectorTypes/DateTimePicker/DateTimePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ describe('DateTimePicker component', () => {
testDateFormat('de-DE', 'MM/DD/YYYY');
});

it('should use the override date format when provided with leading/trailing spaces', () => {
window.contextJsParameters = {
config: {
contentEditor: {
forceDateFormat: ' MM/DD/YYYY '
}
}
};
testDateFormat('de-DE', 'MM/DD/YYYY');
});

it('should NOT use the override date format when an invalid format is provided', () => {
window.contextJsParameters = {
config: {
Expand Down
Loading