Skip to content

Commit 3648b01

Browse files
unazkoilhan007
authored andcommitted
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 6bc84f7 commit 3648b01

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
@@ -415,7 +415,7 @@ class DatePicker extends DateComponentBase {
415415
console.warn(`In order for the "name" property to have effect, you should also: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";`); // eslint-disable-line
416416
}
417417

418-
this.value = this.normalizeValue(this.value);
418+
this.value = this.normalizeValue(this.value) || this.value;
419419
this.liveValue = this.value;
420420
}
421421

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
@@ -1173,4 +1173,11 @@ describe("Date Picker Tests", () => {
11731173
await browser.keys("Backspace");
11741174
await browser.keys("Enter");
11751175
});
1176+
1177+
it("Invalid initial value isn't cleared due to formatting", async () => {
1178+
datepicker.id = "#dp20";
1179+
const input = await datepicker.getInput();
1180+
1181+
assert.equal(await input.getProperty("value"), "Invalid value", "the value isn't changed");
1182+
});
11761183
});

0 commit comments

Comments
 (0)