Open
Labels
area: material/datepickergemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by geminineeds triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Problem
When the default value of a date input is empty, calling control.reset() (which can be called directly or by a parent) does not clear invalid text.
This may be a dupe of #33610 which was closed due to inactivity
Potential Cause
Looks like this may have introduced by a change in the writeValue function on MatDatepickerInputBase
The below will no longer format the input field if the control value is currently empty and the input has invalid text.
writeValue(value: D): void {
// We produce a different date object on each keystroke which can cause signal forms'
// interop logic to keep calling `writeValue` with the same value as the user is typing.
// Skip such cases since they can prevent the user from typing (see #32442 and #32475).
this._assignValueProgrammatically(value, value !== this.value);
}
protected _assignValueProgrammatically(value: D | null, reformat: boolean) {
value = this._dateAdapter.deserialize(value);
this._lastValueValid = this._isValidValue(value);
value = this._dateAdapter.getValidDateOrNull(value);
this._assignValue(value);
// date adapter turns invalid dates to null so `reformat` from `writeValue` is false
if (reformat) {
this._formatValue(value);
}
} In previous versions, _formatValue would always be called.
Reproduction
StackBlitz link: https://stackblitz.com/edit/1hicipgd
Steps to reproduce:
- Enter in any invalid date text into the field tied to a form control
- Call
control.reset()(Reset Datepickerbutton in StackBlitz)
Expected Behavior
Control should reset to default value (empty in this case) and the invalid input text should be cleared
Actual Behavior
Invalid value text remains in the input
Environment
- Angular: 22.2.0
- CDK/Material: 22.2.0
- Browser(s): Chrome 155.0.8059.85
- Operating System: Windows
Metadata
Metadata
Assignees
Labels
area: material/datepickergemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by geminineeds triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team
Activity