diff options
author | Yorhel <git@yorhel.nl> | 2020-11-13 11:37:35 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-11-13 11:37:37 +0100 |
commit | 20011cf2f110d1d89d243ce77b122675463d93b5 (patch) | |
tree | 0e7fa402c0a70bfdc0fc9dd34900574b85acf431 /elm/Lib/Html.elm | |
parent | 6d228704f2e13bccc3c418da5b8ddf537b206ce1 (diff) |
Elm/forms: Fix reporting of validation errors for fields on hidden tabs
https://vndb.org/t950.830
Diffstat (limited to 'elm/Lib/Html.elm')
-rw-r--r-- | elm/Lib/Html.elm | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm index 440abd00..01f5d844 100644 --- a/elm/Lib/Html.elm +++ b/elm/Lib/Html.elm @@ -25,6 +25,8 @@ onInputValidation msg = custom "input" <| targetValue (JD.at ["target", "validity", "valid"] JD.bool) +onInvalid : msg -> Attribute msg +onInvalid msg = on "invalid" (JD.succeed msg) -- Multi-<br> (ugly but oh, so, convenient) br_ : Int -> Html m @@ -33,9 +35,9 @@ br_ n = if n == 1 then br [] [] else span [] <| List.repeat n <| br [] [] -- Quick short-hand way of creating a form that can be disabled. -- Usage: --- form_ Submit_msg (state == Disabled) [contents] -form_ : msg -> Bool -> List (Html msg) -> Html msg -form_ sub dis cont = Html.form [ onSubmit sub ] +-- form_ id Submit_msg (state == Disabled) [contents] +form_ : String -> msg -> Bool -> List (Html msg) -> Html msg +form_ s sub dis cont = Html.form [ id s, onSubmit sub ] [ fieldset [disabled dis] cont ] @@ -155,14 +157,14 @@ inputRadio nam val onch = input ( -- Same as an inputText, but formats/parses an integer as Q### -inputWikidata : String -> Maybe Int -> (Maybe Int -> m) -> Html m -inputWikidata nam val onch = +inputWikidata : String -> Maybe Int -> (Maybe Int -> m) -> List (Attribute m) -> Html m +inputWikidata nam val onch attr = inputText nam (case val of Nothing -> "" Just v -> "Q" ++ String.fromInt v) (\v -> onch <| if v == "" then Nothing else String.toInt <| if String.startsWith "Q" v then String.dropLeft 1 v else v) - [ pattern "^Q?[1-9][0-9]{0,8}$" ] + (pattern "^Q?[1-9][0-9]{0,8}$" :: attr) -- Similar to inputCheck and inputRadio with a label, except this is just a link. |