-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add AtLeastOne constraint and validator #35744
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
Conversation
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
Can you add more tests please? With several constraints, both passing and not passing.
I am not sure about this one because what if I want "at least 2" or "at most 3", etc. I think what you want to achieve is a composition of constraints (ref #35226), right? When we need a composition of different constraints, shouldn't we create a custom constraint reusing core constraints "in context" instead? What about maybe finding another name and add an option to choose the number of constraints that must be valid, so it is at least a bit dynamic? |
Before increasing the complexity we should be sure there is a need for the feature. |
When I started working on this one, I thought about creating a parameter for the number of "internal" constraints, that have to be satisfied. So initially, it was the By the way, I will add more tests soon. |
I don't think AtLeast > 1 serves any use case. |
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.
Can you add more tests please? With several constraints, both passing and not passing.
0b7c2ba
to
6da07dc
Compare
f4acb0e
to
e6209a6
Compare
Thank you @przemyslaw-bogusz. |
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [Validator] Add missing translations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT I forgot about it in the original PR (#35744) - sorry for the extra work. Commits ------- 0c06856 [Validator] Add missing translations
This constraint allows you to apply a collection of constraints to a value, and it will be considered valid, if it satisfies at least one of the constraints from the collection.
Some examples:
The respective default messages would be:
name: This value should satisfy at least one of the following constraints: [1] This value is too short. It should have 5 characters or more. [2] This value should be equal to "bar".
numbers: This value should satisfy at least one of the following constraints: [1] Each element of this collection should satisfy its own set of constraints. [2] This collection should contain exactly 20 elements.
otherNumbers[0]: This value should satisfy at least one of the following constraints: [1] This value should be greater than or equal to 5. [2] This value should be less than or equal to 3.
But of course you could also create a simple custom message like
None of the constraints are satisfied
.