summaryrefslogtreecommitdiff
path: root/elm/Lib/Html.elm
diff options
context:
space:
mode:
Diffstat (limited to 'elm/Lib/Html.elm')
-rw-r--r--elm/Lib/Html.elm24
1 files changed, 16 insertions, 8 deletions
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm
index fd5ebf5d..d2588799 100644
--- a/elm/Lib/Html.elm
+++ b/elm/Lib/Html.elm
@@ -32,16 +32,24 @@ submitButton val state valid load = div []
]
-inputSelect : String -> String -> (String -> m) -> List (Attribute m) -> List (String, String) -> Html m
+inputSelect : String -> a -> (a -> m) -> List (Attribute m) -> List (a, String) -> Html m
inputSelect nam sel onch attrs lst =
- let opt (id, name) = option [ value id, selected (id == sel) ] [ text name ]
+ let
+ opt n (id, name) = option [ value (String.fromInt n), selected (id == sel) ] [ text name ]
+ call first n =
+ case List.drop (Maybe.withDefault 0 <| String.toInt n) lst |> List.head of
+ Just (id, name) -> onch id
+ Nothing -> onch first
+ ev =
+ case List.head lst of
+ Just first -> [ onInput <| call <| Tuple.first first ]
+ Nothing -> []
in select (
- [ tabindex 10
- , onInput onch
- ]
- ++ attrs
- ++ (if nam == "" then [] else [ id nam, name nam ])
- ) <| List.map opt lst
+ [ tabindex 10 ]
+ ++ ev
+ ++ attrs
+ ++ (if nam == "" then [] else [ id nam, name nam ])
+ ) <| List.indexedMap opt lst
inputText : String -> String -> (String -> m) -> List (Attribute m) -> Html m