Last active
October 22, 2016 11:04
-
-
Save nmk/e9fd97dd1a62c04fc52545fec5a9b4ef to your computer and use it in GitHub Desktop.
Revisions
-
nmk revised this gist
Oct 22, 2016 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,14 +12,14 @@ type alias CompanyName = String type Account = Private | Business CompanyName type alias Registration = { email : String , account : Account } @@ -71,11 +71,11 @@ validateRegistration : Validation () Registration validateRegistration = succeed Registration |: ("email" := email) |: (("accountType" := string) `andThen` validateAccount) validateAccount : String -> Validation e Account validateAccount s = case s of "business" -> succeed Business |: ("companyName" := string) -
nmk revised this gist
Oct 22, 2016 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,13 @@ import Html.App as Html import Html.Attributes exposing (..) type alias CompanyName = String type AccountType = Private | Business CompanyName type alias Registration = @@ -27,6 +31,7 @@ type Msg = RegFormMsg Form.Msg main : Program Never main = Html.beginnerProgram { model = { registrationForm = Form.initial [] validateRegistration } @@ -66,7 +71,7 @@ validateRegistration : Validation () Registration validateRegistration = succeed Registration |: ("email" := email) |: (("accountType" := string) `andThen` accountType) accountType : String -> Validation e AccountType -
nmk created this gist
Oct 20, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,122 @@ module Main exposing (..) import Form exposing (Form, FieldState) import Form.Input as Input import Form.Validate exposing (..) import Html exposing (..) import Html.App as Html import Html.Attributes exposing (..) type AccountType = Private | Business String type alias Registration = { email : String , accountType : AccountType } type alias Model = { registrationForm : Form () Registration } type Msg = RegFormMsg Form.Msg main = Html.beginnerProgram { model = { registrationForm = Form.initial [] validateRegistration } , view = view , update = update } view : Model -> Html Msg view { registrationForm } = Html.map RegFormMsg (viewForm registrationForm) update : Msg -> Model -> Model update msg model = case msg of RegFormMsg msg -> { model | registrationForm = Form.update msg model.registrationForm } ---------------------------- (:=) : String -> Validation e a -> Validation e a (:=) = get infixl 7 := (|:) : Validation e (a -> b) -> Validation e a -> Validation e b (|:) = apply validateRegistration : Validation () Registration validateRegistration = succeed Registration |: ("email" := email) |: ("accountType" := string `andThen` accountType) accountType : String -> Validation e AccountType accountType s = case s of "business" -> succeed Business |: ("companyName" := string) _ -> succeed Private radioGroup : List ( String, String ) -> FieldState () String -> Html Form.Msg radioGroup options state = let item ( v, l ) = label [] [ Input.radioInput v state [ value v ], text l ] in p [] (List.map item options) viewForm : Form () Registration -> Html Form.Msg viewForm form = let gS = flip Form.getFieldAsString form isBusiness = (gS "accountType").value == Just "business" in Html.form [] [ pre [] [ text (toString (Form.getOutput form)) ] , Input.dumpErrors form , p [] [ label [] [ text "Email: " , Input.textInput (gS "email") [] ] ] , radioGroup [ ( "private", "Private" ) , ( "business", "Business" ) ] (gS "accountType") , if isBusiness then p [] [ label [] [ text "Company name:" ] , Input.textInput (gS "companyName") [] ] else text "" ]