From 7ec5b5601fd655643ad0fe1120d56bc9b71674f6 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Jun 2016 15:01:14 +0200 Subject: Set up enter form submi behaviour on dialog --- src/client/elm/Dialog/AddPayment/View.elm | 41 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/client/elm/Dialog') diff --git a/src/client/elm/Dialog/AddPayment/View.elm b/src/client/elm/Dialog/AddPayment/View.elm index 96686b8..30df617 100644 --- a/src/client/elm/Dialog/AddPayment/View.elm +++ b/src/client/elm/Dialog/AddPayment/View.elm @@ -38,13 +38,7 @@ view loggedData frequency = , title = getMessage "AddPayment" loggedData.translations , body = \model -> addPaymentForm loggedData model.addPayment , confirm = getMessage "Confirm" loggedData.translations - , confirmMsg = \model -> ( - case Form.getOutput model.addPayment of - Just data -> - Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency) - Nothing -> - Err (Msg.Dialog <| Dialog.UpdateModel <| DialogMsg.AddPaymentMsg <| Form.Submit) - ) + , confirmMsg = submitForm << .addPayment , undo = getMessage "Undo" loggedData.translations } currentDate = Date.fromTime loggedData.currentTime @@ -56,15 +50,24 @@ view loggedData frequency = addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg addPaymentForm loggedData addPayment = - Html.map (Msg.Dialog << Dialog.UpdateModel << DialogMsg.AddPaymentMsg) <| - Html.form - [ class "addPayment" - , onSubmitPrevDefault Form.NoOp - ] - [ Form.textInput loggedData.translations addPayment "payment" "name" - , Form.textInput loggedData.translations addPayment "payment" "cost" - , if Form.frequency addPayment == Punctual - then Form.textInput loggedData.translations addPayment "payment" "date" - else text "" - , Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] - ] + let htmlMap = Html.map (Msg.Dialog << Dialog.Update << DialogMsg.AddPaymentMsg) + in Html.form + [ class "addPayment" + , onSubmitPrevDefault Msg.NoOp + ] + [ htmlMap <| Form.textInput loggedData.translations addPayment "payment" "name" + , htmlMap <| Form.textInput loggedData.translations addPayment "payment" "cost" + , if Form.frequency addPayment == Punctual + then htmlMap <| Form.textInput loggedData.translations addPayment "payment" "date" + else text "" + , htmlMap <| Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] + , Form.hiddenSubmit (submitForm addPayment) + ] + +submitForm : Form String DialogModel.AddPayment -> Msg +submitForm addPayment = + case Form.getOutput addPayment of + Just data -> + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency + Nothing -> + Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg <| Form.Submit -- cgit v1.2.3