Skip to content

Commit

Permalink
Merge 2dd1d01 into 42b6534
Browse files Browse the repository at this point in the history
  • Loading branch information
pekam committed May 6, 2020
2 parents 42b6534 + 2dd1d01 commit f07b363
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/vaadin-date-picker-mixin.html
Expand Up @@ -366,7 +366,7 @@
});
}
};

this.addEventListener('mousedown', bringToFrontListener);
this.addEventListener('touchstart', bringToFrontListener);
}
Expand Down Expand Up @@ -488,7 +488,11 @@
}
const inputValue = selectedDate && formatDate(Vaadin.DatePickerHelper._extractDateParts(selectedDate));
const value = this._formatISO(selectedDate);
this._inputValue = selectedDate ? inputValue : '';

if (!this.__keepInputValue) {
this._inputValue = selectedDate ? inputValue : '';
}

if (value !== this.value) {
this.validate();
this.value = value;
Expand Down Expand Up @@ -682,16 +686,17 @@
// Select the parsed input or focused date
this._ignoreFocusedDateChange = true;
if (this.i18n.parseDate) {
var inputValue = this._inputValue || '';
const inputValue = this._inputValue || '';
const dateObject = this.i18n.parseDate(inputValue);
const parsedDate = dateObject &&
this._parseDate(`${dateObject.year}-${dateObject.month + 1}-${dateObject.day}`);

if (this._isValidDate(parsedDate)) {
this._selectedDate = parsedDate;
} else {
this.__keepInputValue = true;
this._selectedDate = null;
this._inputValue = inputValue;
this.__keepInputValue = false;
}
} else if (this._focusedDate) {
this._selectedDate = this._focusedDate;
Expand Down
11 changes: 11 additions & 0 deletions test/form-input.html
Expand Up @@ -197,6 +197,17 @@
datepicker.close();
});

it('should keep invalid input value during value-changed event', done => {
datepicker.value = '2020-01-01';
inputValue('foo');

datepicker.addEventListener('value-changed', () => {
expect(datepicker._inputValue).to.equal('foo');
done();
});
datepicker.close();
});

it('should validate keyboard input (valid)', done => {
inputValue('01/01/2000');

Expand Down

0 comments on commit f07b363

Please sign in to comment.