You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to validate all properties. But city depends on state being valid, and state depends on country being valid. Name, age, and email are validated independently.
What I want to happen, is that country, name, age, and email get validated first together. Then if country is valid, continue to state, and if state is valid, continue to city.
Or in other words, I want the country -> state -> city to be a sequence, but I want that validator sequence to start along with the validators on the other properties.
What I've tried is to use GroupSequence, with country, name, age, and email in the first group, state in the second, and city in the third. The problem is that if name is invalid, it will not proceed to check state and city, even if the country was valid.
I don't think Sequentially will help, because that performs validation in sequence only on a single property.
I have seen here that groups can be nested, but I think I would need groups nested two levels deep to get the behaviour I want, which isn't supported.
I can't seem to figure out how to do this.
The only thing I can think of is to write a method on the class to perform the logic I want, and validate it with the Callback constraint.
But I like seeing the constraint attributes on the name, age, email properties, and so I would prefer to keep them on the city, state, and country properties as well. I feel it helps with readability, because you can see that this property is validated with this constraint. Otherwise you have to know to look for the callback, and tease out the rules from the code, rather than the attributes.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose I have an entity like this:
I want to validate all properties. But city depends on state being valid, and state depends on country being valid. Name, age, and email are validated independently.
What I want to happen, is that country, name, age, and email get validated first together. Then if country is valid, continue to state, and if state is valid, continue to city.
Or in other words, I want the country -> state -> city to be a sequence, but I want that validator sequence to start along with the validators on the other properties.
What I've tried is to use
GroupSequence, with country, name, age, and email in the first group, state in the second, and city in the third. The problem is that if name is invalid, it will not proceed to check state and city, even if the country was valid.I don't think
Sequentiallywill help, because that performs validation in sequence only on a single property.I have seen here that groups can be nested, but I think I would need groups nested two levels deep to get the behaviour I want, which isn't supported.
I can't seem to figure out how to do this.
The only thing I can think of is to write a method on the class to perform the logic I want, and validate it with the
Callbackconstraint.But I like seeing the constraint attributes on the name, age, email properties, and so I would prefer to keep them on the city, state, and country properties as well. I feel it helps with readability, because you can see that this property is validated with this constraint. Otherwise you have to know to look for the callback, and tease out the rules from the code, rather than the attributes.
Thanks in advance for any suggestions
Beta Was this translation helpful? Give feedback.
All reactions