Skip to content

Commit 304e73b

Browse files
authored
fix(ui5-date-picker): adjust initial value formatting (#4967)
Problem description: When a value string is provided initial with incorrect format patter, then this value gets cleared in the on before rendering hook. Solution: The initial value remains unchanged if the internal formatter isn't able to parse it. Fixes: #4958 Closes: #4958
1 parent 547ce9e commit 304e73b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

packages/main/src/DatePicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class DatePicker extends DateComponentBase {
414414
console.warn(`In order for the "name" property to have effect, you should also: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";`); // eslint-disable-line
415415
}
416416

417-
this.value = this.normalizeValue(this.value);
417+
this.value = this.normalizeValue(this.value) || this.value;
418418
this.liveValue = this.value;
419419
}
420420

packages/main/test/pages/DatePicker_test_page.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<ui5-date-picker id="dp11"></ui5-date-picker>
3737
<ui5-date-picker id="dp13"></ui5-date-picker>
3838
<ui5-date-picker id="dp16" format-pattern="long"></ui5-date-picker>
39+
<ui5-date-picker value="Invalid value" id="dp20"></ui5-date-picker>
3940
<ui5-button id="b1" design="Default">Set date</ui5-button>
4041

4142

packages/main/test/specs/DatePicker.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,4 +1154,11 @@ describe("Date Picker Tests", () => {
11541154
await browser.keys("Backspace");
11551155
await browser.keys("Enter");
11561156
});
1157+
1158+
it("Invalid initial value isn't cleared due to formatting", async () => {
1159+
datepicker.id = "#dp20";
1160+
const input = await datepicker.getInput();
1161+
1162+
assert.equal(await input.getProperty("value"), "Invalid value", "the value isn't changed");
1163+
});
11571164
});

0 commit comments

Comments
 (0)