diff options
author | Yorhel <git@yorhel.nl> | 2019-10-06 11:41:15 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-10-06 11:41:17 +0200 |
commit | 69ffbc08f489770863b80998c704c66f148e469e (patch) | |
tree | 849d4d1bca0a13814b4795274f9a5743c05df036 /elm/Lib/Html.elm | |
parent | 1bed2ce042bab94823550cd90b4e0883710e65de (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.elm | 24 |
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 |