angular / angular/components

feat(datepicker): expose the validators that the datepicker uses internally as a public API

未关闭
#16,274 5 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看
area: material/datepicker feature P3
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

#### Reproduction

https://stackblitz.com/edit/angular-inex9i?file=app%2Fdatepicker-formats-example.ts

#### Steps to reproduce
1. Add a MatDatePicker to a component and bind it to a Reactive form control
2. Ensure you are reporting the built-in parse error (matDatepickerParse) using mat-error
3. Type in a bad date and see the parse error.
4. Call setValidators() on your reactive form control. It doesn't matter what is sent to setValidators
5. Enter invalid data and you will no longer see matDatepickerParse reported


#### Expected Behavior

Parsing errors after calling setValidators() should continue to report parsing errors

#### Actual Behavior

Parsing errors are no longer reported.

#### Additional Information
The provided DateAdapter (custom or not) is still used. However, since [datepicker-input](https://github.com/angular/components/blob/917a52e03cca1b3568d29094bbf430846ba1c3c9/src/material/datepicker/datepicker-input.ts) will provide a null value if the provided DateAdapter says the inputted date is invalid, you cannot workaround this issue with a custom validator.

Many complex forms may have conditional validation so using setValidators is completely expected.

#### Environment

- Angular: 8.0.0
- CDK/Material: 8.0.1
- Browser(s): Google Chrome 73.0.3683.75 (Official Build) (64-bit)
- Operating System Windows 10 64-bit

贡献指南

打开贡献指南

调研方向

从链接的复现步骤和 src/material/datepicker/datepicker-input.ts 开始,重点关注无效的 adapter 输入与 reactive-form validators 之间的交互。当 datepicker 的内部 validators 可通过公共 API 使用,并且在调用 setValidators() 后 matDatepickerParse 错误仍然出现时,此更改即完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。