-
Notifications
You must be signed in to change notification settings - Fork 34
How to validate form fields which should have same values #75
Comments
I have done some further troubleshooting and it seems that reading 2 different fields as I had shown above does not make it possible to track the error in the field's error state. One field is nested into another and the error states are not updated at all when validating the fields. I will appreciate your comments. |
Hi, I think you're quite close, it's just a question of precedence and parenthesis now. I got it working with this adaptation of lib's example:
That could be better, I'm trying to create a helper that would enable us to write |
Great stuff @etaque. This works! Many thanks. |
This was genuinely helpful. I found this thanks to the help from david_hernandez on slack. Maybe this should be part of some example or in the Readme as this serves as a simple example of interdependent validation. |
Hi, Thank you for the great works, this library helped me so much since I need to write a lot of forms views... While working with this validation example, I noticed it was not trivial to show user friendly error messages. Adding Anyway I figured out a workaround and so wanted to share it. Simplified original example: Code on Ellie
Example with user friendly error messages: Code on Ellie
|
Hi @etaque ,
This issue is related to issue 66 which was previously closed.
I have implemented your recommendation on how to do the password confirmation as below:
`validateChangePwdForm : Validation CustomError ChangePwdForm
validateChangePwdForm =
map2 ChangePwdForm
(field "newPassword" validatePassword)
(field "confirmPassword" string |> andThen passwordsMatch)
passwordsMatch : String -> Validation CustomError String
passwordsMatch confirmPassword =
(field "newPassword" string)
|> andThen
(\s ->
if (s /= confirmPassword) then
fail (customError PasswordsMustMatch)
else
succeed s
)`
And I am using the below code to show the error message when the passwords do not much.
`
let
password =
Form.getFieldAsString "confirmPassword" changePwdForm
`
However, I am unable to see the Error message when the input is validated.
What am I doing wrong?
From the troubleshooting I have done so far, it seems that the line
fail (customError PasswordsMustMatch)
is failing to return the validation.
I will appreciate your feedback.
Thanks.
The text was updated successfully, but these errors were encountered: