Skip to content

Commit 14fe357

Browse files
authored
fix(ui5-datepicker): fix the value validation (#1465)
If there is value in the input field and the user removes that vlaue, the component sets "value-state=error" and fires "change" and "input" events with "valid: false" and this is not correct - empty input field should be a valid state.
1 parent cfeed00 commit 14fe357

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/main/src/DatePicker.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ class DatePicker extends UI5Element {
423423

424424
_handleInputChange() {
425425
let nextValue = this._getInput().getInputValue();
426-
const isValid = this.isValid(nextValue);
426+
const emptyValue = nextValue === "";
427+
const isValid = emptyValue || this.isValid(nextValue);
427428
const isInValidRange = this.isInValidRange(this._getTimeStampFromString(nextValue));
428429

429430
if (isValid && isInValidRange) {
@@ -442,7 +443,8 @@ class DatePicker extends UI5Element {
442443

443444
_handleInputLiveChange() {
444445
const nextValue = this._getInput().getInputValue();
445-
const isValid = this.isValid(nextValue) && this.isInValidRange(this._getTimeStampFromString(nextValue));
446+
const emptyValue = nextValue === "";
447+
const isValid = emptyValue || (this.isValid(nextValue) && this.isInValidRange(this._getTimeStampFromString(nextValue)));
446448

447449
this.value = nextValue;
448450
this.fireEvent("input", { value: nextValue, valid: isValid });
@@ -495,8 +497,12 @@ class DatePicker extends UI5Element {
495497

496498
// because the parser understands more than one format
497499
// but we need values in one format
498-
normalizeValue(sValue) {
499-
return this.getFormat().format(this.getFormat().parse(sValue));
500+
normalizeValue(value) {
501+
if (value === "") {
502+
return value;
503+
}
504+
505+
return this.getFormat().format(this.getFormat().parse(value));
500506
}
501507

502508
get validValue() {

0 commit comments

Comments
 (0)