@@ -16,6 +16,7 @@ import {
1616} from '../../src/compat/validation_errors' ;
1717import { CompatFieldNode , getControlStatusSignal } from './compat_field_node' ;
1818import { CompatFieldNodeOptions } from './compat_structure' ;
19+ import { formDebugObj } from '../../src/util/debug' ;
1920
2021// Readonly signal containing an empty array, used for optimization.
2122const EMPTY_ARRAY_SIGNAL = computed ( ( ) => [ ] ) ;
@@ -33,7 +34,25 @@ export class CompatValidationState implements ValidationState {
3334 readonly invalid : Signal < boolean > ;
3435 readonly valid : Signal < boolean > ;
3536
36- readonly parseErrors : Signal < ValidationError . WithFormField [ ] > = computed ( ( ) => [ ] ) ;
37+ readonly parseErrors : Signal < ValidationError . WithFormField [ ] > ;
38+
39+ // Compat fields can't have validation rules applied to them; however, there are other
40+ // features that depend on this property, such as `markAsTouched()`.
41+ readonly shouldSkipValidation : Signal < boolean > ;
42+
43+ /**
44+ * Computes status based on whether the field is valid/invalid/pending.
45+ */
46+ readonly status : Signal < 'valid' | 'invalid' | 'unknown' > ;
47+
48+ readonly rawSyncTreeErrors : Signal < ValidationError . WithFieldTree [ ] > ;
49+ readonly syncErrors : Signal < ValidationError . WithFieldTree [ ] > ;
50+ readonly rawAsyncErrors : Signal < ( ValidationError . WithFieldTree | 'pending' ) [ ] > ;
51+
52+ asyncErrors : Signal < ( ValidationError . WithFieldTree | 'pending' ) [ ] > ;
53+ errorSummary : Signal < ValidationError . WithFieldTree [ ] > ;
54+
55+ private readonly emptyArraySignal : Signal < never [ ] > ;
3756
3857 constructor (
3958 private readonly node : CompatFieldNode ,
@@ -50,26 +69,32 @@ export class CompatValidationState implements ValidationState {
5069 this . invalid = getControlStatusSignal ( options , ( c ) => {
5170 return c . invalid ;
5271 } ) ;
53- }
5472
55- asyncErrors : Signal < ( ValidationError . WithFieldTree | 'pending' ) [ ] > = EMPTY_ARRAY_SIGNAL ;
56- errorSummary : Signal < ValidationError . WithFieldTree [ ] > = EMPTY_ARRAY_SIGNAL ;
73+ this . parseErrors = computed (
74+ ( ) => [ ] ,
75+ ngDevMode ? formDebugObj ( node . debugName , 'parseErrors' ) : undefined ,
76+ ) ;
5777
58- // Those are irrelevant for compat mode, as it has no children
59- rawSyncTreeErrors = EMPTY_ARRAY_SIGNAL ;
60- syncErrors = EMPTY_ARRAY_SIGNAL ;
61- rawAsyncErrors = EMPTY_ARRAY_SIGNAL ;
78+ this . shouldSkipValidation = computed (
79+ ( ) => this . node . hidden ( ) || this . node . disabled ( ) || this . node . readonly ( ) ,
80+ ngDevMode ? formDebugObj ( node . debugName , 'shouldSkipValidation' ) : undefined ,
81+ ) ;
6282
63- // Compat fields can't have validation rules applied to them; however, there are other
64- // features that depend on this property, such as `markAsTouched()`.
65- readonly shouldSkipValidation = computed (
66- ( ) => this . node . hidden ( ) || this . node . disabled ( ) || this . node . readonly ( ) ,
67- ) ;
83+ this . status = computed (
84+ ( ) => calculateValidationSelfStatus ( this ) ,
85+ ngDevMode ? formDebugObj ( node . debugName , 'status' ) : undefined ,
86+ ) ;
6887
69- /**
70- * Computes status based on whether the field is valid/invalid/pending.
71- */
72- readonly status : Signal < 'valid' | 'invalid' | 'unknown' > = computed ( ( ) => {
73- return calculateValidationSelfStatus ( this ) ;
74- } ) ;
88+ this . emptyArraySignal = ngDevMode
89+ ? computed ( ( ) => [ ] , formDebugObj ( node . debugName , 'EMPTY_ARRAY_SIGNAL' ) )
90+ : EMPTY_ARRAY_SIGNAL ;
91+
92+ this . asyncErrors = this . emptyArraySignal ;
93+ this . errorSummary = this . emptyArraySignal ;
94+
95+ // Those are irrelevant for compat mode, as it has no children
96+ this . rawSyncTreeErrors = this . emptyArraySignal ;
97+ this . syncErrors = this . emptyArraySignal ;
98+ this . rawAsyncErrors = this . emptyArraySignal ;
99+ }
75100}
0 commit comments