You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you submitting a bug report or a feature request?
bug report
What is the current behavior?
If we provide an asynchronous function as validate prop to FieldArray component to perform asynchronous validation of field array itself, then unresolved promise is set as FINAL_FORM/array-error for this field. This causes problems if we want to check the form for errors or display an error message because the promise, even if it resolves to "undefined", is in the form's errors object.
What is the expected behavior?
FieldArray's asynchronousvalidate function resolved with:
undefined (null) - field is valid, no errors set as FINAL_FORM/array-error
otherwise - resolved value set as FINAL_FORM/array-error
// gross, but we have to set a string key on the array
;((arrayError: any): Object)[ARRAY_ERROR]=error
returnarrayError
}
}
)
constvalidate: FieldValidator=useConstant(// !!! First change, make validate a Promise()=>async(value,allValues,meta)=>{if(!validateProp)returnundefined;// !!! Second change, resolve eventual Promise before testing if it's a valid error or an arrayconsterror=awaitPromise.resolve(validateProp(value,allValues,meta));if(!error||Array.isArray(error)){returnerror;}constarrayError=[];// gross, but we have to set a string key on the array((arrayError: any): Object)[ARRAY_ERROR]=error;returnarrayError;});
[archive]:
Thanks for the workaround (cf. StackBlitz link above).
For the record:
// `meta` from FieldArray render propconst{ error }=meta;const[resolvedError,setResolvedError]=React.useState();React.useEffect(()=>{Promise.resolve(error).then(setResolvedError);},[error]);
Are you submitting a bug report or a feature request?
bug report
What is the current behavior?
If we provide an asynchronous function as
validate
prop toFieldArray
component to perform asynchronous validation of field array itself, then unresolved promise is set asFINAL_FORM/array-error
for this field. This causes problems if we want to check the form for errors or display an error message because the promise, even if it resolves to "undefined", is in the form's errors object.What is the expected behavior?
FieldArray
's asynchronousvalidate
function resolved with:undefined
(null
) - field is valid, no errors set asFINAL_FORM/array-error
FINAL_FORM/array-error
StackBlitz Link
https://stackblitz.com/edit/react-ts-57t92d?file=App.tsx,components%2FRepeatableField.tsx
What's your environment?
Other information
Synchronous validation work as expected, but not async.
The text was updated successfully, but these errors were encountered: