summaryrefslogtreecommitdiff
path: root/elm/Lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-28 10:54:15 +0100
committerYorhel <git@yorhel.nl>2019-11-10 12:44:55 +0100
commitdc243fb2d89c69611e3c2a154749c14643a69db0 (patch)
treeea63ed1fcb0fa1403781ca60f5344e17d965a671 /elm/Lib
parent279c4c9f82b45863f91a16867e4830695de7e0ce (diff)
ulist: Inline editable votes
Diffstat (limited to 'elm/Lib')
-rw-r--r--elm/Lib/Ffi.elm14
-rw-r--r--elm/Lib/Html.elm7
2 files changed, 17 insertions, 4 deletions
diff --git a/elm/Lib/Ffi.elm b/elm/Lib/Ffi.elm
index 1df0c50f..9c3b1c23 100644
--- a/elm/Lib/Ffi.elm
+++ b/elm/Lib/Ffi.elm
@@ -10,9 +10,15 @@
-- Use sparingly, all of this will likely break in future Elm versions.
module Lib.Ffi exposing (..)
-import Html exposing (Attribute)
-import Html.Attributes exposing (title)
+import Html
+import Html.Attributes
+import Browser.Dom
+import Task
-- Set the innerHTML attribute of a node
-innerHtml : String -> Attribute msg
-innerHtml = always (title "")
+innerHtml : String -> Html.Attribute msg
+innerHtml s = Html.Attributes.title ""
+
+-- Like Browser.Dom.focus, except it can call any function (without arguments)
+elemCall : String -> String -> Task.Task Browser.Dom.Error ()
+elemCall s = Browser.Dom.focus
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm
index edf0a0c5..d9c0594a 100644
--- a/elm/Lib/Html.elm
+++ b/elm/Lib/Html.elm
@@ -12,6 +12,13 @@ import Lib.Api as Api
onClickN : m -> Attribute m
onClickN action = custom "click" (JD.succeed { message = action, stopPropagation = True, preventDefault = True})
+-- onInput that also tells us whether the input is valid
+onInputValidation : (String -> Bool -> msg) -> Attribute msg
+onInputValidation msg = custom "input" <|
+ JD.map2 (\value valid -> { preventDefault = False, stopPropagation = True, message = msg value valid })
+ targetValue
+ (JD.at ["target", "validity", "valid"] JD.bool)
+
-- Multi-<br> (ugly but oh, so, convenient)
br_ : Int -> Html m