Giter Site home page Giter Site logo

iodevs / elm-validate Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 153 KB

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

Elm 96.87% Makefile 0.53% HTML 2.60%
hacktoberfest

elm-validate's People

Contributors

ondrej-tucek avatar s-m-i-t-a avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

elm-review-bot

elm-validate's Issues

Asynchronous validation

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.