Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

forms: validator directives (required, minlength, …) are not applied to a custom control bound with ngModel / formControl

Aperta
#70,721 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
angular, typescript
Ambito
frontend

Direzione di ricerca

Reproduce the issue with the linked StackBlitz, then inspect setupCustomControl and setUpControlValueAccessor in @angular/forms 22.1.6 (fesm2022/forms.mjs). Compare how the two paths handle setUpValidators and verify that required, minlength, maxlength, pattern, email, min, and max report errors on the custom control as they do on a native input.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: forms gemini-triaged
Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

A component with no ControlValueAccessor and a value (or checked) model is bound through NgModel /
FormControlDirective via the custom-control path. Value sync works in both directions, but template validator
directives on that element are never attached: required, minlength, maxlength, pattern, email, min
and max produce no errors and the control stays valid. The same attributes on a native work. Nothing
throws or warns, so a form migrated from a CVA-based control silently starts submitting invalid data.

In @angular/forms 22.1.6 (fesm2022/forms.mjs):

  • setUpControlValueAccessor (1880) calls setUpValidators (1885).
  • NgModel._setUpStandalone / _setupWithForm (3518–3536) call setupCustomControl() instead when
    isCustomControlBased, and setupCustomControl (2147) never calls setUpValidators.
  • ngControlCreate (2171–2192) does find the RequiredValidator (requiredValidatorViaDi), but only uses it for the
    required binding, not as a validator.
    Only validators set on the FormControl itself (e.g. Validators.required) take effect.
Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/jj6trr42?file=src%2Fapp%2Fapp.ts

Please provide the exception or error you saw
None. Expected `custom` and `formControl` to report {"required":true}, like `native`.
Actual: custom: null · native: {"required":true} · formControl: null
Please provide the environment you discovered this bug in (run ng version)
@angular/core 22.1.6, @angular/forms 22.1.6, Node 24.16.0
Anything else?

Workaround: set the validators on the FormControl (Validators.required) instead of as template directives.

Lingua principale
TypeScript
Stelle
101k
Fork
28.1k
Merge medio
2g 6h
PR unite (30g)
307

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di angular/angular

Tutte le issue di angular/angular

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.