iodevs / elm-validate Goto Github PK
View Code? Open in Web Editor NEWElm validation library
Home Page: https://package.elm-lang.org/packages/iodevs/elm-validate/3.0.2
License: BSD 3-Clause "New" or "Revised" License
Elm validation library
Home Page: https://package.elm-lang.org/packages/iodevs/elm-validate/3.0.2
License: BSD 3-Clause "New" or "Revised" License
Hello, sorry for opening an issue but there's no other support/community link.
Apparently I can't perform async validations, for example through a Task. Example at hand, I'm in need to validate an email with a graphql query on the backend to ensure it's not present in the DB.
Some example code to check on the email can be:
checkEmailAddress : Maybe Email -> String -> Task String String
checkEmailAddress emailMaybe emailAddress =
case emailMaybe of
Just { email } ->
Task.fail "Email is taken"
Nothing ->
Task.succeed emailAddress
isTaken : String -> Task String String
isTaken email =
query email
|> Graphql.Http.queryRequest "/graphql"
|> Graphql.Http.toTask
|> Task.mapError(\_ -> "GraphQL error")
|> Task.andThen(\result -> (checkEmailAddress result.user email))
It actually doesn't return a Validator (obviously) and must run as a Cmd.
I'm really struggling to find a solution here, I want to shoow the Command once the field is Valid, this is some quite ugly and badly deisgned code to do that inside InputEmail
InputEmail e ->
( { model
| email =
model.email
|> validate (OnChange e) emailValidation
}
, case validity (model.email |> validate (OnChange e) emailValidation) of
Valid f -> Task.attempt ValidateEmailUniqueness (isTaken f)
_ -> Cmd.none
)
which has the problem that then I don't really have a way to build my own Field as Validator doesn't export Field(..) for example:
ValidateEmailUniqueness emailCheck ->
( { model
| email = case emailCheck of
Ok email -> Field email Valid
Err err -> errorhandling
}
, Cmd.none)
(last snippet is made up)
Did you guys attempt to do anything like this and came up with something better than what I'm doing? Any suggestion?
Link must end with trailing slash.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.