Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Browser
- import Html exposing (..)
- import Html.Events exposing (onClick, onInput)
- import Html.Attributes exposing (placeholder, type_)
- type Msg
- = NoEvent
- | UpdateLoginFormaArchive Int InputField String
- type alias Model =
- { companyName : String
- , loginFormaArchive : LoginFormaArchive
- }
- type alias LoginForma =
- { username : String
- , password : String
- }
- type InputField
- = Username
- | Password
- type alias LoginFormaItem = (Int, LoginForma)
- type alias LoginFormaArchive = List LoginFormaItem
- mkArchiveItem : Int -> LoginFormaItem
- mkArchiveItem i = (i, LoginForma "" "")
- updateLoginForma : LoginFormaArchive -> Int -> InputField -> String -> LoginFormaArchive
- updateLoginForma archive targetId inputField str = List.map
- (\(id, loginForma) -> if id == targetId
- then
- ( id
- , case inputField of
- Username -> { loginForma | username = str }
- Password -> { loginForma | password = str }
- )
- else (id, loginForma)
- )
- archive
- loginFormaItemToHtml : LoginFormaItem -> Html Msg
- loginFormaItemToHtml (i, loginForma) = div []
- [ h1 [] [ text "LogIn" ]
- , input
- [ placeholder "username"
- , onInput <| UpdateLoginFormaArchive i Username
- ]
- []
- , input
- [ placeholder "password"
- , type_ "password"
- , onInput <| UpdateLoginFormaArchive i Password
- ]
- []
- , p [] [ text <| "Entered username is '" ++ loginForma.username ++ "'" ]
- , p [] [ text <| "Entered password is '" ++ loginForma.password ++ "'" ]
- ]
- loginFormaArchiveToHtml : LoginFormaArchive -> Html Msg
- loginFormaArchiveToHtml archive = div [] <| List.map loginFormaItemToHtml archive
- init : Model
- init =
- { companyName = "Google"
- , loginFormaArchive = List.map mkArchiveItem
- [ 0
- , 1
- , 2
- ]
- }
- update : Msg -> Model -> Model
- update msg model = case msg of
- NoEvent -> model
- UpdateLoginFormaArchive id inputField str ->
- { model
- | loginFormaArchive =
- updateLoginForma
- model.loginFormaArchive
- id
- inputField
- str
- }
- view : Model -> Html Msg
- view model = div []
- [ loginFormaArchiveToHtml model.loginFormaArchive
- ]
- main = Browser.sandbox { init = init, update = update, view = view }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement