diff options
author | Joris | 2016-06-26 15:01:14 +0200 |
---|---|---|
committer | Joris | 2016-06-26 15:01:14 +0200 |
commit | 7ec5b5601fd655643ad0fe1120d56bc9b71674f6 (patch) | |
tree | 48dfdb9139cb2d0befdb69595dffdf8462c86b6f /src/client/elm/Dialog | |
parent | 27bf42c165e5a9fa242e0679fca621f2a6dc4adb (diff) |
Set up enter form submi behaviour on dialog
Diffstat (limited to 'src/client/elm/Dialog')
-rw-r--r-- | src/client/elm/Dialog/AddPayment/View.elm | 41 |
1 files changed, 22 insertions, 19 deletions
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 |