angular / angular/components

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

Ouverte
#26,872 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
area: material/datepicker P4
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

### 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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par la page de documentation concernée de AbstractControl.valueChanges et reproduisez le scénario StackBlitz lié. Vérifiez que la modification de min/max du datepicker amène le contrôle associé à émettre un événement, puis mettez à jour la documentation pour décrire ce comportement ; le travail est terminé lorsque la page couvre correctement le cas signalé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
angular, typescript
Domaine
documentation
Type d'issue
Documentation
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.