-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global and input level validation can not be combined #7697
Comments
Thank you for taking the time to update this issue. Actually, it appears that this is a known limitation of the react-hook-form library, and this is documented in the migration guide here:
But, I have to admit this does not appear clearly enough (IMO) in the Form Validation doc. |
@slax57 Well, this is not really convenient and reduce a lot the interest of the input level validation. Here is my use case with a discount code form: const validate: SimpleFormProps['validate'] = (values) => {
const errors: any = {};
if (values.beginAt && values.endAt && values.beginAt >= values.endAt) {
errors.endAt = 'Doit être supérieure à la date de début';
}
return errors;
};
export const DiscountCodeForm: FC<Omit<SimpleFormProps, 'children'>> = (props) => (
<SimpleForm
{...props}
validate={validate}
>
<TextInput
source="code"
validate={[
required(),
minLength(5),
maxLength(20),
regex(/^[a-z0-9]+$/i, 'Uniquement des lettres et des chiffres'),
]}
/>
<TextInput
source="label"
validate={[
required(),
]}
/>
<NumberInput
source="amount"
validate={[
required(),
minValue(0.1),
]}
/>
<DateInput
source="beginAt"
validate={[
required(),
]}
/>
<DateInput
source="endAt"
validate={[
required(),
]}
/>
<ArrayInput
source="whitelist"
helperText="Laisser vide pour autoriser n'importe qui."
>
<SimpleFormIterator>
<TextInput
source=""
label="fields.emailAddress"
/>
</SimpleFormIterator>
</ArrayInput>
</SimpleForm>
); As you can see, I have many required fields, some advanced validation for the If I follow the documentation, then I have to reproduce the same behavior of each function defined in This is very cumbersome and kill the simplicity of react-admin. Don't we have any way to wrap the validation system to apply both react-hook-form validation and the react-admin inline ones? By the way, do we have a link of the Thanks |
I agree. I'll reopen this as an enhancement feature so that we can discuss with the team what we can do about this. |
Thanks! By the way, I share to you two information:
|
Okay, so. We have tried to overcome limitations of third-party libs by the past, but this really turned out to be a pain, so for this problem we highly suggest you open an issue on the react-hook-form tracker, asking them to support this. Regarding your latest comment, indeed the doc needs to be fixed. |
Hi @slax57 and thanks for the feedback. For now I just remove the global validation as we use it only once. We will work on a better API related validation displaying, so we don't have concrete case for the moment. Because of that, I won't look further for now. I suggest to keep that issue open, maybe you can ask About #7690, I didn't even try for the previous reason. I was struggling with another more important upgrade issues. 😉 |
#7726 has been merged and fixes the documentation part. Keeping this open as an enhancement request. |
I'm closing this as the enhancement should come from the react-hook-form side. |
This is a follow up of #6270, closed because of a v3 environment bug report: #6270 (comment)
@andrico1234 the behavior I reported before is for v4, so here is a new one! :-)
What you were expecting:
Using both global and input level validations on a same form should merge the behavior.
What happened instead:
Only the global validation is executed
Steps to reproduce:
make run-simple
foo
The "Author" form should trigger an error because of
minLength(10)
input level configuration.Related code:
pocivaneuh#2
Other information:
Environment
The text was updated successfully, but these errors were encountered: