Advertisement
DoctorRynerNew

Untitled

Oct 27th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import Browser
  2. import Html exposing (..)
  3. import Html.Events exposing (onClick, onInput)
  4. import Html.Attributes exposing (placeholder, type_)
  5.  
  6. type Msg
  7. = NoEvent
  8. | UpdateLoginFormaArchive Int InputField String
  9.  
  10. type alias Model =
  11. { companyName : String
  12. , loginFormaArchive : LoginFormaArchive
  13. }
  14.  
  15. type alias LoginForma =
  16. { username : String
  17. , password : String
  18. }
  19.  
  20. type InputField
  21. = Username
  22. | Password
  23.  
  24. type alias LoginFormaItem = (Int, LoginForma)
  25.  
  26. type alias LoginFormaArchive = List LoginFormaItem
  27.  
  28. mkArchiveItem : Int -> LoginFormaItem
  29. mkArchiveItem i = (i, LoginForma "" "")
  30.  
  31. updateLoginForma : LoginFormaArchive -> Int -> InputField -> String -> LoginFormaArchive
  32. updateLoginForma archive targetId inputField str = List.map
  33. (\(id, loginForma) -> if id == targetId
  34. then
  35. ( id
  36. , case inputField of
  37. Username -> { loginForma | username = str }
  38. Password -> { loginForma | password = str }
  39. )
  40. else (id, loginForma)
  41. )
  42. archive
  43.  
  44. loginFormaItemToHtml : LoginFormaItem -> Html Msg
  45. loginFormaItemToHtml (i, loginForma) = div []
  46. [ h1 [] [ text "LogIn" ]
  47. , input
  48. [ placeholder "username"
  49. , onInput <| UpdateLoginFormaArchive i Username
  50. ]
  51. []
  52. , input
  53. [ placeholder "password"
  54. , type_ "password"
  55. , onInput <| UpdateLoginFormaArchive i Password
  56. ]
  57. []
  58. , p [] [ text <| "Entered username is '" ++ loginForma.username ++ "'" ]
  59. , p [] [ text <| "Entered password is '" ++ loginForma.password ++ "'" ]
  60. ]
  61.  
  62. loginFormaArchiveToHtml : LoginFormaArchive -> Html Msg
  63. loginFormaArchiveToHtml archive = div [] <| List.map loginFormaItemToHtml archive
  64.  
  65.  
  66.  
  67. init : Model
  68. init =
  69. { companyName = "Google"
  70. , loginFormaArchive = List.map mkArchiveItem
  71. [ 0
  72. , 1
  73. , 2
  74. ]
  75. }
  76.  
  77. update : Msg -> Model -> Model
  78. update msg model = case msg of
  79. NoEvent -> model
  80. UpdateLoginFormaArchive id inputField str ->
  81. { model
  82. | loginFormaArchive =
  83. updateLoginForma
  84. model.loginFormaArchive
  85. id
  86. inputField
  87. str
  88. }
  89.  
  90. view : Model -> Html Msg
  91. view model = div []
  92. [ loginFormaArchiveToHtml model.loginFormaArchive
  93. ]
  94.  
  95. main = Browser.sandbox { init = init, update = update, view = view }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement