File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -1891,6 +1891,55 @@ describe('field api', () => {
1891
1891
expect ( form . state . canSubmit ) . toBe ( true )
1892
1892
} )
1893
1893
1894
+ it ( 'should not block onChangeAsync of a field when onChangeListenTo is used in another field' , async ( ) => {
1895
+ const syncErrorMessage = 'Sync error triggered'
1896
+ const asyncErrorMessage = 'An Async Error was triggered'
1897
+
1898
+ const nameValidators = {
1899
+ onChange : ( { value } : { value : string } ) => ! value && syncErrorMessage ,
1900
+ onChangeAsyncDebounceMs : 500 ,
1901
+ onChangeAsync : async ( { value } : { value : string } ) =>
1902
+ value . includes ( 'error' ) && asyncErrorMessage ,
1903
+ } as const
1904
+
1905
+ vi . useFakeTimers ( )
1906
+
1907
+ const form = new FormApi ( {
1908
+ defaultValues : {
1909
+ firstName : '' ,
1910
+ lastName : '' ,
1911
+ } ,
1912
+ } )
1913
+
1914
+ form . mount ( )
1915
+
1916
+ const firstNameField = new FieldApi ( {
1917
+ form,
1918
+ name : 'firstName' ,
1919
+ validators : {
1920
+ ...nameValidators ,
1921
+ } ,
1922
+ } )
1923
+
1924
+ const lastNameField = new FieldApi ( {
1925
+ form,
1926
+ name : 'lastName' ,
1927
+ validators : {
1928
+ ...nameValidators ,
1929
+ onChangeListenTo : [ 'firstName' ] , // FIXME - commenting out this line will make the test pass
1930
+ } ,
1931
+ } )
1932
+
1933
+ firstNameField . mount ( )
1934
+ lastNameField . mount ( )
1935
+
1936
+ firstNameField . setValue ( 'error' )
1937
+
1938
+ await vi . runAllTimersAsync ( )
1939
+
1940
+ expect ( firstNameField . getMeta ( ) . errors ) . toContain ( asyncErrorMessage )
1941
+ } )
1942
+
1894
1943
it ( 'should debounce onChange listener' , async ( ) => {
1895
1944
vi . useFakeTimers ( )
1896
1945
const form = new FormApi ( {
You can’t perform that action at this time.
0 commit comments