Skip to content

Commit

Permalink
fix: keep invalid _inputValue during value-changed event (#722)
Browse files Browse the repository at this point in the history
fix #721
  • Loading branch information
pekam committed May 7, 2020
1 parent 42b6534 commit 3076dfc
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3076dfc

Please sign in to comment.