-
-
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
Question: How to do multiple checks for password validation with Yup and RFH? #26
Comments
we do actually support |
Thanks @bluebill1049 for the quick reply. Going to try that quickly now to see if that is what I am looking for. Will post here and close out if it works :) |
I am pretty new to RFH and Yup looking at the types, I am not seeing
This is what it is expecting:
I will do some more digging / googling, but just wanted. to let you know what I was trying. |
Hey @sngreg! I think if you add
I haven't actually tested it but it seems like the solution to me. |
@Mathius17 - Thanks for the suggestion. I did set it to false and am experiencing the same result above, where the password errors will trigger, but only shows one of each "type" so for reference: I have 4 different .matches regex but it only fires the first one. Also. for reference - it looks like the YupResolver defaults aboutEarly:false already - https://github.com/react-hook-form/resolvers/blob/master/src/yup.ts#L45 |
Hi @sngreg so yes for the |
Thanks @Vandell63 - I was afraid this might be the case after all the digging I was doing. I appreciate everyone jumping into this discussion. |
You welcome, i think you can close it, and as soon as yup want to add this feature, i'm pretty sure that @bluebill1049 will be already on :) . |
@Vandell63 @bluebill1049 - Thank you again for the really quick responses. Vandell63 - I opened an issue on yup (jquense/yup#975) which it looks like this is not a problem in yup. Here is a very quick sample that shows ALL the errors when we call yup.validate. https://codesandbox.io/s/nice-brown-61nzg Notice in the console:
I believe this something with how RHF or the resolver handles these errors and makes the object to return Thoughts? |
@sngreg Im so sorry to lead you to the bad way. Effectively yup return an array of all errors ( log on codesandbox an Error class lead me to a weird log ). |
@Vandell63 no worries at all! Glad we are able to narrow this down. Thanks for starting that, i have narrowed it down to the EX: Parse Inner Reduce ---- This is the start of the inner.reduce, but after what the function returns is: Which only has one of the "Matches" TYPES |
I believe this is where the error is happening, it only appends the latest error of a type: https://github.com/react-hook-form/resolvers/blob/master/src/yup.ts#L15 Looking at what this does https://github.com/react-hook-form/react-hook-form/blob/173e0c1740108d23101681d79000708c5a2b7778/src/logic/appendErrors.ts#L21 It overwrites the type I tested this out adding a random number to type in the resolver and it. "solved" the issue. I am not sure the best approach to where a permeant should live, is appendError in RFH functioning as intended (not to duplicate types) or is this something we should fix in the resolver? Thoughts? |
thanks for the invitation @sngreg i haven't got time to look too deep on this one, do you have any fix in mind since you already traveled this deep into the code. |
Thanks Bill! I don’t have a fix in mind. I know why it is broken but not sure how or where to fix. I know it is the appendError in RHF code. One thought if we are fixing in resolvers can we build a unique list before appending them, or build our own error list. |
@sngreg Yes this is the case for the
In the code if you switch the |
Thanks, @Vandell63 for all the support and investigation. I am really appreciated it here. |
@bluebill1049 is totally normal, you are really active and we all like this. And i have to switch from formik to this library ( performance reason ). And no way for me i stay here. |
@bluebill1049 & @sngreg I got a working example of @sngreg needs on
Et voilà. But im pretty sure that it will work for this issue. I don't know how it could impact into the |
yes i think we can remove: transformToNestObject. can you create a PR and let's do some further testing and see if this impact other stuff or not. |
@bluebill1049 same here i will give a try :) |
@Vandell63 - Thank you so much, taking a look now to see what you made and trying it out in my application. |
@bluebill1049 @Vandell63 This is exactly what I needed. Things are looking good in my application, but I think the way we have this now will introduce a breaking change for people that have coded for the old type: Now all the fields in the schema return an array of errors (GREAT!) but prior to this change their was the top level error exposed and then an object called types to. see the "partial / broken" list AFTER: (Note the screenshots are not 1-1 in regards to the same schema, but you understand the thought behind it) So if anyone is display label / field messages for their form it will break because One thought to enhance this change and not introduce it as a breaking change would be an object like this
|
@bluebill1049 - So with the thoughts of keeping the object the same, I agree. We run into issues using the type as the key in matches-1: 'Special' |
Hey after a diving session into react hook form i didnt find any deps with the props |
@Vandell63 - this looks great to me! I like that we keep the same object type and just repurpose the types array with “all” the validation criteria. I am new to this repo, but I think you should make a PUll request with this code and see what @bluebill1049 thinks! I appreciate all the time, intelligent discussion, and collaboration we all put towards this feature. |
@sngreg thx same feeling. |
yea totally! thanks for all the investigations. looking forward to your PRs, this is going to help some many developers. |
Thanks @Vandell63 - Bill's always one step ahead of me! |
@sngreg i think we have to wait for a decision and the PR too to be sync on . And take in mind that the ui do not refresh on new yup errors from the same types. It work when message was a Array. So the current example refresh the ui if one of the key appear or disappear base on yup errors. |
Thanks @Vandell63 - In my use case, I will need the UI to refresh to give live feedback on the password criteria. I agree, lets see what Bill and Kotarella1110 has to say in RFH and then work on our solution |
@bluebill1049 @Vandell63 - looks like the PR is merged in RHFs (thanks for doing that) - Bill - would you like us to submit a PR to this repo now with the final structure that we talked about using types and message arrays? I still think this resolver should return an array for every message in the types key (like we were going to do for messages) |
@Vandell63 okay that works, so basically, the type is the key and if there is only one message it is
But if multiple messages it is
That works for me, I just like to be consistent as possible with value types but works for my scenario |
@sngreg I saw that the types are merge to rhf but for this repo nothing has change yet right ? Or am i missing something |
@Vandell63 based on looking at open / closed PRa nothing has changed. That being said not sure if bill or kota are working in it? |
@sngreg please create this PR 👍 |
@Vandell63 do you have a PR started, if not I can look into making one. (I don’t want to duplicate the efforts) |
looking forward for the PR. thanks 👍 |
@sngreg sorry not yet, do want me to give a try ? |
@Vandell63 if you have time today sure. I looked at the code sandbox and I think we are almost there. I am using the latest code sandbox and was working as intended. |
@sngreg @bluebill1049 @kotarella1110 i let you a video instead of hundred of wording. Codesandbox link -> https://codesandbox.io/s/yup-resolver-with-errors-array-0js7s?file=/src/Inputs/Object.js |
@Vandell63 thanks for making the video and the code! This looks great to me. Looking forward to the PR! |
@bluebill1049 @sngreg there we go -> #32 |
@sngreg are you happy with the new release 0.1.0 ? If yes we should maybe close this issue ? |
@Vandell63 Yes! Everything works great! Thanks @Vandell63 / @bluebill1049 / @kotarella1110 for the quick work and the release. Closing this issue out. |
@sngreg, @Vandell63, @bluebill1049 |
I think it's because of fe53179#diff-1c9dbc45c6880a5a6b5aef346c662825aa881277d91717d88cd8aae0cd35bcc4. |
Can you share a codesanbox with your problem please ? |
Hi, Joris. Thanks for your quick reply.
https://codesandbox.io/s/react-hook-form-basic-forked-60bno?file=/src/index.js
React Hook Form - Basic (forked) - CodeSandbox
This is example with my problem.
Kind Regards
Jason
…On 13 Apr 2021, 15:29 +0100, Joris ***@***.***>, wrote:
Hi @codemaster115
Can you share a codesanbox with your problem please ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Thanks for the codesandbox @codemaster115 The issue: #155 |
Thank you, @jorisre |
I am wondering if there is a way with yup and yupResolver with RHF to do something similar to this:
https://codesandbox.io/s/eager-bush-dfl5t
Basically using this code when a user starts typing into the password field you get separated booleans for each validation criteria which allows you to build an interactive component such as:
Code that I have been playing around with:
Which results in:
I was hoping to have types returned like the coding sample so I can flag the realtime critera.
Any help or things in yup would be super helpful.
Thanks!
The text was updated successfully, but these errors were encountered: