summaryrefslogtreecommitdiff
path: root/elm/Lib/Html.elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-06 11:41:15 +0200
committerYorhel <git@yorhel.nl>2019-10-06 11:41:17 +0200
commit69ffbc08f489770863b80998c704c66f148e469e (patch)
tree849d4d1bca0a13814b4795274f9a5743c05df036 /elm/Lib/Html.elm
parent1bed2ce042bab94823550cd90b4e0883710e65de (diff)
Elm: Support arbitrary id types in inputSelect + actually honor the selected option
Elm has a bug where the 'selected' attribute is not properly propagated, that's fixed by patching the generated JS. Also moved Ffi.js one level up, as it's important that that file is loaded before any Elm modules are initialized.
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