aboutsummaryrefslogtreecommitdiff
path: root/src/client/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/View')
-rw-r--r--src/client/View/Events.elm19
-rw-r--r--src/client/View/Payments/Add.elm20
-rw-r--r--src/client/View/SignIn.elm17
3 files changed, 39 insertions, 17 deletions
diff --git a/src/client/View/Events.elm b/src/client/View/Events.elm
new file mode 100644
index 0000000..1eb9027
--- /dev/null
+++ b/src/client/View/Events.elm
@@ -0,0 +1,19 @@
+module View.Events
+ ( onSubmitPrevDefault
+ ) where
+
+import Signal
+import Json.Decode as Json
+import Html exposing (..)
+import Html.Events exposing (..)
+import Html.Attributes exposing (..)
+
+onSubmitPrevDefault : Signal.Address a -> a -> Attribute
+onSubmitPrevDefault address value =
+ onWithOptions
+ "submit"
+ { defaultOptions | preventDefault <- True }
+ Json.value
+ (\_ ->
+ Signal.message address value
+ )
diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm
index f2230be..32010ef 100644
--- a/src/client/View/Payments/Add.elm
+++ b/src/client/View/Payments/Add.elm
@@ -2,20 +2,28 @@ module View.Payments.Add
( addPayment
) where
-import Html exposing (..)
+import Html as H exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
+import Reads exposing (readInt)
+import Result exposing (..)
-import ServerCommunication as SC
-import ServerCommunication exposing (serverCommunications)
+import ServerCommunication as SC exposing (serverCommunications)
import Update exposing (..)
import Update.Payment exposing (..)
+import View.Events exposing (onSubmitPrevDefault)
+
addPayment : String -> String -> Html
addPayment name cost =
- div
- [ class "add" ]
+ H.form
+ [ class "add"
+ , onSubmitPrevDefault serverCommunications.address
+ <| case readInt cost of
+ Ok number -> SC.AddPayment name number
+ Err _ -> SC.NoCommunication
+ ]
[ text "Name"
, input
[ value name
@@ -29,6 +37,6 @@ addPayment name cost =
]
[]
, button
- [ onClick serverCommunications.address (SC.AddPayment name cost) ]
+ [ type' "submit" ]
[ text "Add" ]
]
diff --git a/src/client/View/SignIn.elm b/src/client/View/SignIn.elm
index 02ee1bd..a45adc7 100644
--- a/src/client/View/SignIn.elm
+++ b/src/client/View/SignIn.elm
@@ -2,7 +2,7 @@ module View.SignIn
( renderSignIn
) where
-import Html exposing (..)
+import Html as H exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
@@ -16,20 +16,21 @@ import ServerCommunication exposing (serverCommunications)
import Model.View.SignInView exposing (..)
+import View.Events exposing (onSubmitPrevDefault)
+
renderSignIn : SignInView -> Html
renderSignIn signInView =
div
[ class "signIn" ]
- [ div
- [ class "form" ]
+ [ H.form
+ [ onSubmitPrevDefault serverCommunications.address (SC.SignIn signInView.login) ]
[ input
[ value signInView.login
, on "input" targetValue (Signal.message actions.address << UpdateSignIn << UpdateLogin)
- , onEnter serverCommunications.address (SC.SignIn signInView.login)
]
[]
, button
- [ onClick serverCommunications.address (SC.SignIn signInView.login) ]
+ []
[ text "Sign in" ]
]
, div
@@ -37,12 +38,6 @@ renderSignIn signInView =
[ signInResult signInView ]
]
-onEnter : Signal.Address a -> a -> Attribute
-onEnter address value =
- on "keydown"
- (Json.customDecoder keyCode (\code -> if code == 13 then Ok () else Err ""))
- (\_ -> Signal.message address value)
-
signInResult : SignInView -> Html
signInResult signInView =
case signInView.result of