Closed taj closed 5 years ago
README.md says:
Functions the detect something wrong with a value, such as
isNotInt
andisInvalidEmail
, accept a function as the second argument so you can include the incorrect value in the error message:
modelValidator : Validator ( Field, String ) Model
modelValidator =
Validate.all
[ ifNotInt .count (\value -> ( Count, value ++ " is not an integer." ))
, ifInvalidEmail .email (\value -> ( Email, value ++ " is not a valid email address." ))
]
So you need to pass a function that takes the incorrect value and returns your tuple. (It can ignore that value, but you have to make a function).
Thanks @thiloplanz
I will make a pull request to fix the documentation!
I've created a Pull Request to correct the documentation and the Sign Up Form example.
I tried the example examples/SignupForm.elm
in Ellie but got a bunch of errors, does this have the same reason that the example might not be updated to latest revision?
https://ellie-app.com/474hyJ4MKTya1
if so, what should the validate be like than?
result : Bool
result =
validate modelValidator
{ name = "Sam", email = "", age = "abc", selections = [ 1.2 ] }
== [ ( Email, "Please enter an email address." )
, ( Age, "Age must be a whole number." )
]
gives error
The left side of (==) is:
Result (List ( Field, String )) (Validate.Valid Model)
But the right side is:
List ( Field, String )
Different types can never be equal though! Which side is messed up?
The documentaion is not updated to the latest release:
change you're code to:
ifInvalidEmail .email (\_ -> ( Email, "This is not a valid email address.") )
and
ifNotInt .age ( \_ -> ( Age, "Age must be a whole number. )" )
to fix it
I get an error when trying to implement the
ifInvalidEmail
validator.Here's my code (that I copied from the Sign Up Form Example):
and the error is:
Same thing happens for
ifNotInt
validators.