forms: validator directives (required, minlength, …) are not applied to a custom control bound with ngModel / formControl
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
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
requiredbinding, 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di angular/angular
-
area: docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
area: forms forms: signals
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
area: docs gemini-triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
area: forms forms: signals
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
area: docs area: forms
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Tutte le issue di angular/angular
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
TanStack/tanstack.com#1293 ·