angular / angular/components

bug(material/datepicker): Adding a max to a datepicker input will fire valueChanges

Đang mở
#26,872 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
area: material/datepicker P4
Ngôn ngữ chính
TypeScript
Star
25k
Fork
6.8k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
91

Mô tả

### Documentation Feedback

Currently the [documentation ](https://angular.io/api/forms/AbstractControl#valueChanges)only says that valueChanges will fire 'every time the value of the control changes' or 'each time you call enable() or disable()' however, I've also found valueChanges to fire if two inputs with datepickers rely upon one another for min and max.

My scenario is a period that has a start and end date. The start date cannot be after the end date, similarly the end date cannot be before the start. So basically my two form fields look like this:

```

```
and
```

```

What I've found is that the valueChanges of startDate will emit whenever the endDate is changed because of the startDate max.

It doesn't seem obvious in the documentation that setting the mib or max will cause the value of the control to change.

Here's a [stackblitz](https://stackblitz.com/edit/reactive-form-validation-angular-15-swfz9e?file=src/app/app.component.html).

Steps to reproduce:

1: Select a start date and see that its value is logged to the console via the valueChanges subscription on startDate.
2: Now make a change to the endDate field and note that the startDate valueChanges emits again.
3: Remove the [max]="period.get('endDate')?.value" from the startDate input and notice that the issue goes away.

### Affected documentation page

https://angular.io/api/forms/AbstractControl#valueChanges

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với trang tài liệu AbstractControl.valueChanges bị ảnh hưởng và tái hiện kịch bản StackBlitz được liên kết. Xác nhận rằng khi thay đổi min/max của datepicker, control liên quan sẽ phát sự kiện, sau đó cập nhật tài liệu để mô tả hành vi đó; công việc được xem là hoàn tất khi trang mô tả chính xác trường hợp được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.