criteriaMode: formLevel #6472
Replies: 9 comments 36 replies
-
Sounds good to me. Two questions: Would these errors be placed in the |
Beta Was this translation helpful? Give feedback.
-
Question: do we need to flush out all the form errors when the inputs are mounted or until the user interacts with the inputs? The difference is pretty much whether we invoke trigger() instead of the lib at |
Beta Was this translation helpful? Give feedback.
-
With |
Beta Was this translation helpful? Give feedback.
-
I'm a little confused by this one, although I think I like the idea - can you explain how you would document/explain formLevel vs the existing firstError vs all? (a table comparison might help, as in what setting has what behavior) If it's what I think it is, I can see this being a commonly desired behavior and one the devs would sacrifice perf for vs the clearer user behavior. I feel I've likely made my forms work this way at times using mode and revalidateMode but having this more "built in" would be nice. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how this is a performance hit. The reason being is that we decide what validation we want to perform. All this is really doing is giving us access to errors that are already being computed by our validation (to get Perhaps with built-in validation, it's more expensive if there are some optimizations. However, with schema validation, it is still being run the way we decide each time. For example, the user can use the If anything this seems like it would be faster because we don't remove parse the schema result object and remove non-field errors. As mentioned above we can return it closer to how it is. |
Beta Was this translation helpful? Give feedback.
-
One question I have is should we place this under For example, we could have multiple form-level errors. Ex: we want to make sure a field array that consists of a single text input has at least 4 inputs and all the text in the inputs are unique. With the To me, this seems like something that either should be set by default or a separate option. Again given my performance note above, I'm not sure how adding this would affect the performance. For example, if you don't care about form-level validation, then don't add any validation rules. Otherwise, we are already doing the work to compute it so I don't see how giving us the error message adds much more work. |
Beta Was this translation helpful? Give feedback.
-
I guess the way I see this working, is we simply don't omit paths from
So therefore what I would like to see is in my
Whether we use |
Beta Was this translation helpful? Give feedback.
-
I'm not quite sure if it is related to this topic, but since I got linked to here from 6858 and I see that After digging a bit deeper into my confusion about 6858, I figured, that validation is working differently if the input is field level. When I compare it with field arrays: In both validation does run as defined in Is this related? If so, how come the validation is run anyway, but the error is not stored/reflected? |
Beta Was this translation helpful? Give feedback.
-
here is an improved version: https://codesandbox.io/s/react-hook-form-fieldsarray-yup-validation-forked-6f6ih?file=/src/src/useFieldArray.ts
|
Beta Was this translation helpful? Give feedback.
-
Context
React Hook Form focus on performance and user experience, which is a result of why the lib has quite precise on when to re-render your components. For example, if the input contains an error, we will trigger exactly one re-render to info the component to update, and exactly one re-render when the input's error gets resolved (instead of spamming the re-render). This is one of the reasons hook form is unique and more performant than most of the form libraries in the industry. The also reflects on form state update. However, we would like to expand that option to users, and allow users to have validation at the form level. So what are some of the impacts on such config:
Props
Cons
mode
&reValidateMode
will be ignoredProposal
Related issues
#4356
react-hook-form/resolvers#243
cc @jorisre @kotarella1110 @barrymay
Beta Was this translation helpful? Give feedback.
All reactions