@@ -11,6 +11,7 @@ import {TestBed} from '@angular/core/testing';
1111import {
1212 form ,
1313 FormField ,
14+ maxError ,
1415 transformedValue ,
1516 validate ,
1617 type FormValueControl ,
@@ -304,6 +305,25 @@ describe('parse errors', () => {
304305 expect ( errors1 ) . toEqual ( [ ] ) ;
305306 expect ( input1 . value ) . toBe ( '42' ) ;
306307 } ) ;
308+
309+ it ( 'should preserve parse errors when transformedValue parse returns both value and errors' , async ( ) => {
310+ @Component ( {
311+ imports : [ TestNumberInput , FormField ] ,
312+ template : `<test-number-input [parseMax]="10" [formField]="f" />` ,
313+ } )
314+ class TestCmp {
315+ state = signal < number | null > ( 5 ) ;
316+ f = form ( this . state ) ;
317+ }
318+
319+ const fix = await act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
320+ const comp = fix . componentInstance ;
321+ const input : HTMLInputElement = fix . nativeElement . querySelector ( 'input' ) ! ;
322+
323+ input . value = '11' ;
324+ await act ( ( ) => input . dispatchEvent ( new Event ( 'input' ) ) ) ;
325+ expect ( comp . f ( ) . errors ( ) ) . toEqual ( [ jasmine . objectContaining ( { kind : 'max' } ) ] ) ;
326+ } ) ;
307327} ) ;
308328
309329@Component ( {
@@ -318,6 +338,7 @@ describe('parse errors', () => {
318338class TestNumberInput implements FormValueControl < number | null > {
319339 readonly value = model . required < number | null > ( ) ;
320340 readonly errors = input < readonly ValidationError [ ] > ( [ ] ) ;
341+ readonly parseMax = input < number | undefined > ( undefined ) ;
321342
322343 protected readonly rawValue = transformedValue ( this . value , {
323344 parse : ( rawValue ) => {
@@ -326,6 +347,9 @@ class TestNumberInput implements FormValueControl<number | null> {
326347 if ( Number . isNaN ( value ) ) {
327348 return { errors : [ { kind : 'parse' , message : `${ rawValue } is not numeric` } ] } ;
328349 }
350+ if ( this . parseMax ( ) != null && value > this . parseMax ( ) ! ) {
351+ return { value, errors : [ maxError ( this . parseMax ( ) ! ) ] } ;
352+ }
329353 return { value} ;
330354 } ,
331355 format : ( value ) => {
0 commit comments