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
Say I have two fields field_a and field_b, field_b is optional by default but it becomes required when field_a has certain values.
I've been looking at the existing validators and it seems it only receives the node that it should validate, how can I access other nodes within the same schema from a validator?
The text was updated successfully, but these errors were encountered:
I'm over three years late to this thread but there is (now?!) another way to do this!
Use a deferred that conditionally returns colander.required:
@colander.deferreddefconditionally_required(node, kw):
some_condition=# whatever conditional logic you wantifsome_condition:
returncolander.drop# won't be required (or return a default like `None`)returncolander.required# will be required
This can then be used as the missing value when defining a schema node:
As a concrete example, if you have the request bound to your schema as kw['request'] and you wanted to make foo required unless a field called action has the value cheat, you could use:
How can I achieve conditional validation?
Say I have two fields field_a and field_b, field_b is optional by default but it becomes required when field_a has certain values.
I've been looking at the existing validators and it seems it only receives the node that it should validate, how can I access other nodes within the same schema from a validator?
The text was updated successfully, but these errors were encountered: