Skip to content
Discussion options

You must be logged in to vote

I've finally found the solution:

<Button
     onClick={(e) => {
          append({ fromDepth: "", toDepth: "" }, { shouldFocus: false });
         // calling formMethods.trigger here does nothing because the new fieldArray element has not yet been rendered. 
         // For some reason the validation and the generating of the errors appear to be not connected, because the validation 
         // works already by calling `append`
     }}
>

Hence we have to call trigger after rendering with useEffect:

  useEffect(() => {
    formMethods.trigger("fieldArray");
  }, [formMethods.getValues().fieldArray]);

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tschumpr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
status: need more detail Please follow our issue template.
3 participants
Converted from issue

This discussion was converted from issue #11568 on March 04, 2024 20:56.