-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Support multiple errors messages #32
Support multiple errors messages #32
Conversation
c0977e0
to
dba4bb9
Compare
oh man! thanks very much for your amazing contribution, I will take a look at the PR. 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great testing coverage!
Thanks @pmaier983 I will take a look at the PR tonight as well. solid effort @Vandell63 ❤️ |
src/yup.test.ts
Outdated
expect(resolve.errors['password'].types).toMatchInlineSnapshot(` | ||
Object { | ||
"matches": Array [ | ||
"Special", | ||
"Number", | ||
"Uppercase", | ||
"Lowercase", | ||
], | ||
"min": Array [ | ||
"password must be at least 8 characters", | ||
], | ||
"required": Array [ | ||
"password is a required field", | ||
], | ||
} | ||
`); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The structure I had in mind was:
expect(resolve.errors['password'].types).toMatchInlineSnapshot(`
Object {
"matches": Array [
"Special",
"Number",
"Uppercase",
"Lowercase",
],
"min": "password must be at least 8 characters",
"required": "password is a required field",
}
`);
We should discuss whether all should be array message when validateAllFieldCriteria
is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kotarella1110. Above is a breaking change, we should stick with
expect(resolve.errors['password'].types).toMatchInlineSnapshot(`
Object {
"matches": Array [
"Special",
"Number",
"Uppercase",
"Lowercase",
],
"min": "password must be at least 8 characters",
"required": "password is a required field",
}
`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bluebill1049 I agree with you 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i was thinking if we keep this mix structure, i'm afraid that we have to handle the case where messages
can be an array or a string in the code for every property in the schema. This is why i keep every messages in array format when validateAllCriteria
is set to true. But you are in better place to take the right decision here :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for understanding and putting this PR together!
Thx you . As much as the time you gave me when i was in trouble |
src/__snapshots__/yup.test.ts.snap
Outdated
"types": Object { | ||
"required": "age is a required field", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If validateAllFieldCriteria is false, types
field shouldn't be included.
src/__snapshots__/yup.test.ts.snap
Outdated
"types": Object { | ||
"min": "name is a min field", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@Vandell63 I have created a PR (Paul-Vandell#1) to take my feedback comment above. |
@kotarella1110 sry i was thinking that @bluebill1049 will make some changes too. So if i understood, you want the props
|
I will commit the No.5 fix to the PR I created.
yes. I think we should keep mixed types.
What do @bluebill1049 think about this ?
This is under consideration. Please give me some time.
we should fix this 👍 |
Yes totally 👍 |
Thanks @kotarella1110 for the review, sorry i was busy and haven't look close enough, i will make sure to do that tonight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comments as @kotarella1110 thank for the PR 👍
src/yup.ts
Outdated
Array.isArray(error.inner) && error.inner.length | ||
? error.inner.reduce<FieldErrors<TFieldValues>>( | ||
(previous, { path, message, type }) => { | ||
const previousPath = previous[path] as FieldErrors | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use this variable inline (save few bytes)
src/yup.ts
Outdated
type, | ||
types: previousTypes, | ||
}), | ||
types: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types
should be optional.
@Vandell63 @bluebill1049 please review this PR (Paul-Vandell#1). |
Done @kotarella1110 |
…ple-errors-message
Thank @bluebill1049 @kotarella1110 merge done. |
@bluebill1049 @kotarella1110 Oh i maybe forget this. In yup errors the path seems to be never |
I finally added test and #32 (comment) logic. |
I think it would be better to centralize the |
actually, from memory they do get |
@bluebill1049 Totally agree 👍 |
So @bluebill1049 @kotarella1110 should you prefer:
It can be all of them.
|
@Vandell63 Does option 2 mean this? values: await schema.validate(values, {
- context,
...options,
+ context,
}) as any, I prefer all of them. |
Oh sorry @kotarella1110 , no in the code it could be
Remove context property from yup option if user is not in typescript it could still add context props into. Just to be sure. |
shall we do 1 and 3?
|
@bluebill1049 I agree 👍 |
@bluebill1049 @kotarella1110 ok for me i will propose you a final commit with test as soon as i can . |
Thank you very much. no rush whenever you are free. |
@bluebill1049 a pleasure for me no worry |
@bluebill1049 @kotarella1110 there we go.
|
b08757d
to
e998e69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Let's go! thanks @kotarella1110 's review and @Vandell63's hard work! do you have a twitter account? let's tweet this new feature. |
Yess it was so cool thx . let's go this new fresh twitter -> https://twitter.com/Paul_Vandell. |
@Vandell63 @bluebill1049 @kotarella1110 - THANK you so much this code looks great. Sorry I went MIA for a couple of days, I was out of the office on vacation. This feature is a GREAT add to this repo! |
criteriaMode: "all"
At the same time:
inner error
of an empty array. So it always return any errors. Now we check if inner errors is an empty array or not. If no please return only one error at a time. Test has been done for this. it could help resolve issue from -> feat(context): inject context into yup context #30 (comment) where yup validation return anything.types
is always defined it can be an empty array too.Improvements which can be done into
transformToNestObject
we will have at the same time array errors and all field errors inside this array.Cons: errors duplication :
Pros: it can be interesting to have it to get at the same time array errors and fields errors in.
We could maybe do :
validateAllFieldCriteria ? call transformToNestObject
You can have example of use case here -> #26 (comment)
From issue -> #26
it could help issue like -> #30 (comment)