react-final-form-arrays icon indicating copy to clipboard operation
react-final-form-arrays copied to clipboard

Asynchronous `validate` prop of `FieldArray` put unresolved promise as `FINAL_FORM/array-error` instead of resolved value

Open usavkov-epam opened this issue 2 years ago • 1 comments

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 asynchronous validate 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

StackBlitz Link

https://stackblitz.com/edit/react-ts-57t92d?file=App.tsx,components%2FRepeatableField.tsx

What's your environment?

{
    "final-form": "^4.20.7",
    "final-form-arrays": "^3.0.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-final-form": "^6.5.9",
    "react-final-form-arrays": "^3.1.4",
  }

Other information

Synchronous validation work as expected, but not async.

usavkov-epam avatar Nov 18 '22 20:11 usavkov-epam