From 9c4835a94263127f780c0b96db89aa25ceefd960 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 27 Nov 2019 13:45:22 +0100 Subject: Elm: Use fieldset to disable the form while loading I wasn't able to do this while the .maintabs used floats. --- elm/DocEdit.elm | 2 +- elm/Lib/Html.elm | 8 ++++++++ elm/StaffEdit/Main.elm | 2 +- elm/User/Edit.elm | 2 +- elm/User/Login.elm | 2 +- elm/User/PassReset.elm | 2 +- elm/User/PassSet.elm | 2 +- elm/User/Register.elm | 2 +- 8 files changed, 15 insertions(+), 7 deletions(-) (limited to 'elm') diff --git a/elm/DocEdit.elm b/elm/DocEdit.elm index 0d654e59..ef4ce715 100644 --- a/elm/DocEdit.elm +++ b/elm/DocEdit.elm @@ -80,7 +80,7 @@ update msg model = view : Model -> Html Msg view model = - Html.form [ onSubmit Submit ] + form_ Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| "Edit d" ++ String.fromInt model.id ] , table [ class "formtable" ] diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm index 6e67cefb..86c0f8f7 100644 --- a/elm/Lib/Html.elm +++ b/elm/Lib/Html.elm @@ -31,6 +31,14 @@ br_ : Int -> Html m 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 ] + [ fieldset [disabled dis] cont ] + + inputButton : String -> m -> List (Attribute m) -> Html m inputButton val onch attrs = input ([ type_ "button", class "submit", tabindex 10, value val, onClick onch] ++ attrs) [] diff --git a/elm/StaffEdit/Main.elm b/elm/StaffEdit/Main.elm index 2eeaea27..9765f0c0 100644 --- a/elm/StaffEdit/Main.elm +++ b/elm/StaffEdit/Main.elm @@ -200,7 +200,7 @@ view model = ] in - Html.form [ onSubmit Submit ] + form_ Submit (model.state == Api.Loading) [ div [ class "mainbox staffedit" ] [ h1 [] [ text "General info" ] , table [ class "formtable" ] diff --git a/elm/User/Edit.elm b/elm/User/Edit.elm index aec74d50..1a13cdb1 100644 --- a/elm/User/Edit.elm +++ b/elm/User/Edit.elm @@ -174,7 +174,7 @@ view model = else formField "uniname::Display name" [ inputText "uniname" (if data.uniname == "" then data.username else data.uniname) (Set << Uniname) GUE.valUniname ] ] - in Html.form [ onSubmit Submit ] + in form_ Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| if data.authmod then "Edit " ++ data.username else "My preferences" ] , table [ class "formtable" ] <| diff --git a/elm/User/Login.elm b/elm/User/Login.elm index e3771777..bef69cb5 100644 --- a/elm/User/Login.elm +++ b/elm/User/Login.elm @@ -141,7 +141,7 @@ view model = ] ] - in Html.form [ onSubmit Submit ] + in form_ Submit (model.state == Api.Loading) [ if model.insecure then changeBox else loginBox , div [ class "mainbox" ] [ fieldset [ class "submit" ] [ submitButton "Submit" model.state True False ] diff --git a/elm/User/PassReset.elm b/elm/User/PassReset.elm index f22a16c8..ad265c87 100644 --- a/elm/User/PassReset.elm +++ b/elm/User/PassReset.elm @@ -68,7 +68,7 @@ view model = [ p [] [ text "Your password has been reset and instructions to set a new one should reach your mailbox in a few minutes." ] ] ] else - Html.form [ onSubmit Submit ] + form_ Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Forgot Password" ] , p [] diff --git a/elm/User/PassSet.elm b/elm/User/PassSet.elm index a04cfe33..3c5c50bc 100644 --- a/elm/User/PassSet.elm +++ b/elm/User/PassSet.elm @@ -70,7 +70,7 @@ update msg model = view : Model -> Html Msg view model = - Html.form [ onSubmit Submit ] + form_ Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Set your password" ] , p [] [ text "Now you can set a password for your account. You will be logged in automatically after your password has been saved." ] diff --git a/elm/User/Register.elm b/elm/User/Register.elm index abbf5d63..d4749e47 100644 --- a/elm/User/Register.elm +++ b/elm/User/Register.elm @@ -78,7 +78,7 @@ view model = [ p [] [ text "Your account has been created! In a few minutes, you should receive an email with instructions to set your password." ] ] ] else - Html.form [ onSubmit Submit ] + form_ Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Create an account" ] , table [ class "formtable" ] -- cgit v1.2.3