summaryrefslogtreecommitdiff
path: root/elm/Lib
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
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')
-rw-r--r--elm/Lib/Ffi.elm2
-rw-r--r--elm/Lib/Ffi.js9
-rw-r--r--elm/Lib/Html.elm24
3 files changed, 17 insertions, 18 deletions
diff --git a/elm/Lib/Ffi.elm b/elm/Lib/Ffi.elm
index 6a2a5364..1df0c50f 100644
--- a/elm/Lib/Ffi.elm
+++ b/elm/Lib/Ffi.elm
@@ -5,7 +5,7 @@
-- This module is a hack to work around the lack of an FFI (Foreign Function
-- Interface) in Elm. The functions in this module are stubs, their
-- implementations are replaced by the Makefile with calls to
--- window.elmFfi_<name> and the actual implementations are in Ffi.js.
+-- window.elmFfi_<name> and the actual implementations are in 1-ffi.js.
--
-- Use sparingly, all of this will likely break in future Elm versions.
module Lib.Ffi exposing (..)
diff --git a/elm/Lib/Ffi.js b/elm/Lib/Ffi.js
deleted file mode 100644
index 86418d97..00000000
--- a/elm/Lib/Ffi.js
+++ /dev/null
@@ -1,9 +0,0 @@
-window.elmFfi_innerHtml = function(wrap) { // \s -> _VirtualDom_property('innerHTML', _Json_wrap(s))
- return function(s) {
- return {
- $: 'a2',
- n: 'innerHTML',
- o: wrap(s)
- }
- }
-};
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