Skip to content

Commit

Permalink
BACKLOG-23452: Trim the date format when configured (#1786)
Browse files Browse the repository at this point in the history
When a date format is configured in Content Editor (contentEditor.forceDateFormat property), trim its value to loose restrictions on this property (as the value must be 'MM/DD/YYYY' or 'DD/MM/YYYY').
  • Loading branch information
baptistegrimaud authored Jan 10, 2025
1 parent 427b91e commit 370ed67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 370ed67

Please sign in to comment.