-
Notifications
You must be signed in to change notification settings - Fork 819
feat: make IsOptional
conditional
#689
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
base: develop
Are you sure you want to change the base?
Conversation
This is stuck for too much time.. can save a lot effort of writing custom validators which not always work.. |
Please merge this pr |
this repo is not maintained, I ended up copying the relevant code to my project |
Please rebase to review. |
a3401b2
to
ef3942b
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.
Nice feature! I think we need to determine if we want this to co-exist with the general validation condition argument that has been proposed (for all validators) in #1579
I'm not sure, myself.
@IsOptional(item => item.age === 34)
versus
@IsOptional({ skip: item => item.age === 34 })
@@ -800,7 +821,7 @@ isBoolean(value); | |||
| ------------------------------------------------| ----------- | | |||
| **Common validation decorators** | | | |||
| `@IsDefined(value: any)` | Checks if value is defined (!== undefined, !== null). This is the only decorator that ignores skipMissingProperties option. | | |||
| `@IsOptional()` | Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property. | | |||
| `@IsOptional(condition?: function)` | Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property. | |
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.
Perhaps an explanation of the condition argument would be appreciated here?
What is the difference to ValidateIf? |
@Clashsoft this is the difference: |
Please, aprove this PR! It's must needed |
@NoNameProvided can we merge this one? It is very useful validator and people use different workarounds to use it. I am sure community will be thankful for this one 🙌 |
See my recent comment in #1721 |
Description
This is a modified copy of the old PR #196.
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
fixes #651