-
Notifications
You must be signed in to change notification settings - Fork 22
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
It does not work if "data" value is an empty object. #27
Comments
Hello! Thanks a lot for your input. That behaviour was recently changed to not fail if validating empty objects. As this library is based on Laravel I might revert this decision on the next release. I'll leave this issue open until that new release is published. |
Hello 👋 The current behavior will stay as I believe that if no data is present then there is nothing to validate even if that's laravel default behavior. If you do not agree with this feel free to tell me. I'll close the issue for now. Thanks, |
Hi Joao. I ended using other validation solution. Thanks. Keep on going with this library. Regards. |
I'm sorry to reply to an old thread but I think this is a bad decision. We just updated our dependency to 1.1.2 and some validations stop working due to this. I'll explain why I think this is a bad decision. We'll take one of our situation as an exemple: We have a POST request containing only one field. So, our code look like this: const validator = Validator.make(req.body, {
foo: "required",
}); So, this validation stop working if we receive a call on our endpoint without the only one and required field! Now, we need to do something like that: if (validator.fails() || Object.keys(req.body).length === 0) {
...
} Or just drop the validator... Could you re-think your decision please? |
Let me see If I understood correctly.
Is that it? :) |
No, the validation don't fail now with the latest version, if we pass an
empty object. Even if the object doesn't have the required field, the
validation don't fail (so it's in success which is not true)
Le jeu. 27 mai 2021 21 h 22, João Faustino ***@***.***> a
écrit :
… Let me see If I understood correctly.
1. You are trying to validate an object that should have a foo
property, therefore required.
2. Validations fails because an object without that property, foo was
passed?
Is that it? :)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#27 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEBYSM4JXGWVIZEOIOL7ONTTP3V6NANCNFSM4PO6XGWQ>
.
|
I'll look at this and get back to you this weekend. |
I'll revert this decision on the next release. |
@jfstn Thanks a lot 👍 |
@guyaumetremblay I will release a new version today that fixes this behavior.
Thank you. |
Hey, good library. I'm very used to Laravel, so this implementation of yours is a good help.
I found probably an issue regarding if "data" is an empty object or not. Right now I'm working with Express, and after noticing that I'm receiving an empty object from req.body, I cannot make the validator fails.
Is this the intended behaviour? If I recall correctly, in Laravel if a Validation.make() instance does not receive a filled value, the fails() method gets called. This is not happening with this implementation. I mean, I think if we are validating some rules against empty/null/undefined data the validator should fail.
Steps to reproduce:
Result:
The text was updated successfully, but these errors were encountered: