Closed ronjunevaldoz closed 2 years ago
@ronjunevaldoz did this answer your question?
Note that the snippet suffers from the issue described in #37.
Also, the addConstraint can be directly applied to the outer Validation<SignupFormDto>
. This means it can be simplified to:
data class SignupFormDto(val password: String?, val confirmPassword: String?)
val validator = Validation<SignupFormDto> {
SignupFormDto::password required {}
SignupFormDto::confirmPassword required {}
addConstraint("Passwords should match") {
if (it.password == null || it.confirmPassword == null) {
true // dont whine about non matching passwords when not filled in yet
} else {
it.password == it.confirmPassword
}
}
}
println(validator(SignupFormDto("Secret", "NoSecret")))
// Invalid(errors=[ValidationError(dataPath=, message=Passwords should match)])
println(validator(SignupFormDto("Secret", "Secret")))
// Valid(value=SignupFormDto(password=Secret, confirmPassword=Secret))
Closing because of inactivity.
I hope this helps:
I've not tested this, but I hope this helps you. Sorry for the late response, I've only just learned about this library.