react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

ArrayInput validation does not prevent submission or update isValid

Open ZachSelindh opened this issue 3 years ago • 2 comments

What you were expecting: Validation passed directly to ArrayInput to work properly as with other inputs on the form.

What happened instead: This is probably related to issue #7591, but that issue points directly to validation for ArrayInput's children, while this issue deals with the validation passed to ArrayInput specifically. Validation does not prevent submission and does not update the form context, such as "isValid".

Steps to reproduce: Pass validation such as required() to an ArrayInput.

Related code: https://codesandbox.io/s/condescending-colden-vic0fn?file=/src/posts/PostCreate.tsx

Navigate to the Post create form, and observe in the console that the Backlinks ArrayInput does not prevent "isValid" from updating to "true" when the other required inputs are filled, whether there is a value for Backlinks or not.

Set variable RETURN_REQUIRED to "false" and observe that my custom validation receives the form values properly, and even updates the helperText if a Backlink is added and removed, but does not return the error to the form to prevent submission.

Environment

  • React-admin version: 4.1.5
  • Last version that did not exhibit the issue (if applicable): 3.19
  • React version: 17
  • Browser: Chrome
  • Stack trace (in case of a JS error):

ZachSelindh avatar Jun 22 '22 14:06 ZachSelindh

Reproduced thanks for reporting!

antoinefricker avatar Jun 23 '22 09:06 antoinefricker

As an update to this issue: I'm using a custom toolbar that calls react-hook-form's trigger() method to get invalid inputs from the form. This method does not currently return an error for a "required" ArraryInput on the form.

ZachSelindh avatar Jun 23 '22 15:06 ZachSelindh

Ticket closed, PR #8080 solves the problem.

arimet avatar Aug 22 '22 09:08 arimet