@@ -2986,6 +2986,88 @@ describe('form api', () => {
2986
2986
expect ( interestsField . state . meta . errors ) . toStrictEqual ( [ ] )
2987
2987
} )
2988
2988
2989
+ it ( "clears form's onMount validation field errors on next form validation" , async ( ) => {
2990
+ const form = new FormApi ( {
2991
+ defaultValues : {
2992
+ firstName : '' ,
2993
+ middleName : '' ,
2994
+ lastName : '' ,
2995
+ } ,
2996
+ validators : {
2997
+ onChange : ( { value } ) => {
2998
+ return {
2999
+ fields : {
3000
+ firstName : value . firstName !== 'john' ? 'first name is not john' : null ,
3001
+ lastName : 'last name is required' ,
3002
+ }
3003
+ }
3004
+ } ,
3005
+ onMount : ( ) => {
3006
+ return {
3007
+ fields : {
3008
+ firstName : 'first name is required' ,
3009
+ lastName : 'last name is required' ,
3010
+ }
3011
+ }
3012
+ } ,
3013
+ } ,
3014
+ } )
3015
+
3016
+ const firstNameField = new FieldApi ( {
3017
+ form,
3018
+ name : 'firstName' ,
3019
+ } )
3020
+
3021
+ const middleNameField = new FieldApi ( {
3022
+ form,
3023
+ name : 'middleName' ,
3024
+ validators : {
3025
+ onMount : ( ) => 'middle name is required' ,
3026
+ } ,
3027
+ } )
3028
+
3029
+ const lastNameField = new FieldApi ( {
3030
+ form,
3031
+ name : 'lastName' ,
3032
+ } )
3033
+
3034
+ firstNameField . mount ( )
3035
+ middleNameField . mount ( )
3036
+ lastNameField . mount ( )
3037
+ form . mount ( )
3038
+
3039
+ expect ( firstNameField . state . meta . errorMap . onMount ) . toBe ( 'first name is required' )
3040
+ expect ( firstNameField . state . meta . errorSourceMap . onMount ) . toBe ( 'form' )
3041
+
3042
+ expect ( middleNameField . state . meta . errorMap . onMount ) . toBe ( 'middle name is required' )
3043
+ expect ( middleNameField . state . meta . errorSourceMap . onMount ) . toBe ( 'field' )
3044
+
3045
+ expect ( lastNameField . state . meta . errorMap . onMount ) . toBe ( 'last name is required' )
3046
+ expect ( lastNameField . state . meta . errorSourceMap . onMount ) . toBe ( 'form' )
3047
+
3048
+ firstNameField . setValue ( 'other' )
3049
+
3050
+ expect ( firstNameField . state . meta . errorMap . onChange ) . toEqual ( 'first name is not john' )
3051
+ expect ( firstNameField . state . meta . errorSourceMap . onMount ) . toBeUndefined ( )
3052
+
3053
+ expect ( middleNameField . state . meta . errorMap . onMount ) . toBe ( 'middle name is required' )
3054
+ expect ( middleNameField . state . meta . errorSourceMap . onMount ) . toBe ( 'field' )
3055
+
3056
+ expect ( lastNameField . state . meta . errorMap . onMount ) . toBeUndefined ( )
3057
+ expect ( lastNameField . state . meta . errorSourceMap . onMount ) . toBeUndefined ( )
3058
+
3059
+ firstNameField . setValue ( 'john' )
3060
+
3061
+ expect ( firstNameField . state . meta . errorMap . onMount ) . toBeUndefined ( )
3062
+ expect ( firstNameField . state . meta . errorSourceMap . onMount ) . toBeUndefined ( )
3063
+
3064
+ expect ( middleNameField . state . meta . errorSourceMap . onMount ) . toBe ( 'field' )
3065
+ expect ( middleNameField . state . meta . errorMap . onMount ) . toBe ( 'middle name is required' )
3066
+
3067
+ expect ( lastNameField . state . meta . errorMap . onMount ) . toBeUndefined ( )
3068
+ expect ( lastNameField . state . meta . errorSourceMap . onMount ) . toBeUndefined ( )
3069
+ } )
3070
+
2989
3071
it ( 'should not change the onBlur state of the fields when the form is submitted' , async ( ) => {
2990
3072
const form = new FormApi ( {
2991
3073
defaultValues : {
0 commit comments