diff options
author | Yorhel <git@yorhel.nl> | 2019-10-02 14:21:12 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-10-02 14:21:15 +0200 |
commit | 7d8274f0332b1c92825988c6393037bf7eb12af3 (patch) | |
tree | cdcc33c92f764b3199fffeef990d71e6085dff06 /elm/Lib/Html.elm | |
parent | 1a9a4b4bdb8f3b6d7d0ad12032c17c44a8287a09 (diff) |
v2rw: Convert user preferences form
And add a small 'formField' function to shrink the Elm form generation
code a bit.
Diffstat (limited to 'elm/Lib/Html.elm')
-rw-r--r-- | elm/Lib/Html.elm | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm index 41f6e376..fd5ebf5d 100644 --- a/elm/Lib/Html.elm +++ b/elm/Lib/Html.elm @@ -13,6 +13,10 @@ onClickN : m -> Attribute m onClickN action = custom "click" (JD.succeed { message = action, stopPropagation = True, preventDefault = True}) +-- Multi-<br> (ugly but oh, so, convenient) +br_ : Int -> Html m +br_ n = if n == 1 then br [] [] else span [] <| List.repeat n <| br [] [] + -- Submit button with loading indicator and error message display submitButton : String -> Api.State -> Bool -> Bool -> Html m submitButton val state valid load = div [] @@ -85,3 +89,26 @@ inputCheck nam val onch = input ( ] ++ (if nam == "" then [] else [ id nam, name nam ]) ) [] + + +-- Generate a form field (table row) with a label. The `label` string can be: +-- +-- "none" -> To generate a full-width field (colspan=2) +-- "" -> Empty label +-- "Some string" -> Text label +-- "input::String" -> Label that refers to the named input +-- +-- (Yeah, stringly typed arguments; I wish Elm had typeclasses) +formField : String -> List (Html m) -> Html m +formField lbl cont = + tr [ class "newfield" ] + [ if lbl == "none" + then text "" + else + td [ class "label" ] + [ case String.split "::" lbl of + [name, txt] -> label [ for name ] [ text txt ] + txt -> text <| String.concat txt + ] + , td (class "field" :: if lbl == "none" then [ colspan 2 ] else []) cont + ] |