Skip to content
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

Combinator for additional validation logic #37

Open
k-bx opened this issue Dec 27, 2018 · 0 comments
Open

Combinator for additional validation logic #37

k-bx opened this issue Dec 27, 2018 · 0 comments

Comments

@k-bx
Copy link

k-bx commented Dec 27, 2018

Hi, sorry if I've missed this somehow in existing API.

I have this part of form which is only displayed if the "trafficking" checkbox is checked, so I need to validate its fields only then. I couldn't figure out how to do this without exporting the Validator(..) constructors for matching. Currently I did it like this:

ifTraffickingEnabled : Validator error { subject | trafficking : Bool } -> Validator error { subject | trafficking : Bool }
ifTraffickingEnabled validator =
    V.Validator
        (\subject ->
            if subject.trafficking then
                let
                    (V.Validator f) =
                        validator
                in
                f subject

            else
                []
        )

modelValidator : Validator ( Field, String ) Model
modelValidator =
  V.all
    [ ...
    , ifTraffickingEnabled (V.ifNothing .totalBudget ( TotalBudget, "Can't be empty" ))
    ]

Did I miss something? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant