Skip to content

Instantly share code, notes, and snippets.

@ngw

ngw/Update.elm Secret

Created March 14, 2018 13:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ngw/60d445db3332086cf11eba8404a10e83 to your computer and use it in GitHub Desktop.
init : (Model, Cmd Message)
init =
( { form = Form.initial initialFields validate
, showPassword = False
, emailTaken = False
, userMaybe = Nothing }
, output (Dict.toList designerRoleOptions) )
update : Message -> Model -> (Model, Cmd Message)
update message ({ form } as model) =
case message of
NoOp ->
( model, Cmd.none )
ValidateEmailUniqueness response ->
case response of
Ok _ ->
( model, Cmd.none )
Err _ ->
( { model | emailTaken = True }, Cmd.none )
FormMsg formMsg ->
let
form_ = Form.update validate formMsg form
user_ = Form.getOutput form_
_ = Debug.log "FORM" formMsg
in
case formMsg of
Form.Input "user[type]" Form.Radio (Form.Field.String userType) ->
({ model | form = Form.update validate formMsg form_ }, switchToUserType userType )
Form.Input "user[email]" Form.Text (Form.Field.String string) ->
let
emailField = Form.getFieldAsString "user[email]" form_
request = emailValidationRequest emailField.value
in
case emailField.error of
Nothing ->
(model, Http.send ValidateEmailUniqueness request)
_ ->
(model, Cmd.none)
Form.Input "togglePassword" Form.Checkbox string ->
({ model | showPassword = not model.showPassword }, Cmd.none )
_ ->
({ model | form = form_, userMaybe = user_ }, Cmd.none)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment