-
Notifications
You must be signed in to change notification settings - Fork 39
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
How to achieve Password matching? #35
Comments
I hope this helps: val validator = Validation<SignupFormDto> {
SignupFormDto::password required {}
SignupFormDto::confirmPassword required {}
val checkPasswordsMatch = Validation<SignupFormDto> {
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
}
}
}
SignupFormDto::discountedPlanPriceUntil {
run(checkPasswordsMatch)
}
} I've not tested this, but I hope this helps you. Sorry for the late response, I've only just learned about this library. |
@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 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. |
in the above example it does't show dataPath value. I wanted to show the error for confirmPassword CreateBasicAccountInput::confirmPassword required {
addConstraint("Passwords should match") {
it.password == it.confirmPassword
}
} |
@ronjunevaldoz see #29 |
No description provided.
The text was updated successfully, but these errors were encountered: