Skip to content

fix(material/datepicker): clear invalid text when the form value is reset - #33979

Open
Arul1998 wants to merge 1 commit into
angular:mainfrom
Arul1998:fix/datepicker-reset-invalid-text
Open

Arul1998 wants to merge 1 commit into
angular:mainfrom
Arul1998:fix/datepicker-reset-invalid-text

Conversation

@Arul1998

Copy link
Copy Markdown

Fixes #33978.

Problem

writeValue skipped re-formatting the input when the incoming value was the same as the current one. This was added in #32447 and #32485 to work around signal forms writing the same value back into the CVA while the user was typing (#32442, #32475).

As a side effect, an unparseable value could no longer be cleared programmatically. After the user types something like foo, the model value is null, so reset() / setValue(null) calls writeValue(null) with the value that's already there and gets skipped. The invalid text stays in the input, and because _lastValueValid is reset, no matDatepickerParse error is shown either. Signal forms reset() goes through the same path and is affected as well.

Fix

Angular 22.0.0 deduplicates writeValue calls in the CVA interop (angular/angular@2e9aeea0f), and @angular/material 22 requires @angular/core ^22.0.0, so the workaround is no longer needed. This PR removes it so writeValue always re-formats the input, and drops the now-unused reformat parameter from _assignValueProgrammatically.

Tests

I also checked it manually in an Angular / Material 22.2.3 app, before and after patching:

Scenario Before After
Reactive forms: type foo, then reset() foo stays cleared
Reactive forms: type bar, then setValue(null) bar stays cleared
Signal forms: type foo, then reset() foo stays cleared
Signal forms: type foo kept kept
Signal forms: type 1 → 1/ → … → 1/1/2026 not clobbered not clobbered
Signal forms with debounce: same typing sequences not clobbered not clobbered
Programmatic valid date (reactive and signal) formatted formatted

…eset

`writeValue` skipped re-formatting the input when the incoming value was
the same as the current one. This was added in angular#32447 and angular#32485 to work
around signal forms writing the same value back into the CVA while the
user was typing (angular#32442, angular#32475). As a side effect, calling `reset()` or
`setValue(null)` after the user typed an unparseable date left the
invalid text in the input without a parse error. Signal forms `reset()`
was affected as well.

Angular 22.0.0 deduplicates `writeValue` calls in the CVA interop
(angular/angular@2e9aeea0f), so the workaround is no longer necessary.
These changes remove it so that `writeValue` always re-formats the input.

Fixes angular#33978.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(matDatePickerInput): invalid values are not cleared on control.reset

1 participant