mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 05:13:24 +03:00
Update form parsing logic with new server form parsers.
This commit is contained in:
parent
a106496052
commit
255cd8c6a4
30
src/Form.elm
30
src/Form.elm
@ -903,7 +903,17 @@ runOneOfServerSide :
|
|||||||
List ( String, String )
|
List ( String, String )
|
||||||
-> ServerForms error parsed
|
-> ServerForms error parsed
|
||||||
-> ( Maybe parsed, Dict String (List error) )
|
-> ( Maybe parsed, Dict String (List error) )
|
||||||
runOneOfServerSide rawFormData (ServerForms parsers) =
|
runOneOfServerSide rawFormData forms =
|
||||||
|
runOneOfServerSideHelp rawFormData Nothing forms
|
||||||
|
|
||||||
|
|
||||||
|
{-| -}
|
||||||
|
runOneOfServerSideHelp :
|
||||||
|
List ( String, String )
|
||||||
|
-> Maybe (List ( String, List error ))
|
||||||
|
-> ServerForms error parsed
|
||||||
|
-> ( Maybe parsed, Dict String (List error) )
|
||||||
|
runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
|
||||||
case parsers of
|
case parsers of
|
||||||
firstParser :: remainingParsers ->
|
firstParser :: remainingParsers ->
|
||||||
let
|
let
|
||||||
@ -918,15 +928,23 @@ runOneOfServerSide rawFormData (ServerForms parsers) =
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
case thing of
|
case thing of
|
||||||
( Just parsed, [] ) ->
|
( Just parsed, errors ) ->
|
||||||
( Just parsed, Dict.empty )
|
( Just parsed, errors |> Dict.fromList )
|
||||||
|
|
||||||
_ ->
|
( Nothing, errors ) ->
|
||||||
runOneOfServerSide rawFormData (ServerForms remainingParsers)
|
runOneOfServerSideHelp rawFormData
|
||||||
|
(firstFoundErrors
|
||||||
|
-- TODO is this logic what we want here? Might need to think through the semantics a bit more
|
||||||
|
-- of which errors to parse into - could be the first errors, the last, or some other way of
|
||||||
|
-- having higher precedence for deciding which form should be used
|
||||||
|
|> Maybe.withDefault errors
|
||||||
|
|> Just
|
||||||
|
)
|
||||||
|
(ServerForms remainingParsers)
|
||||||
|
|
||||||
[] ->
|
[] ->
|
||||||
-- TODO need to pass errors
|
-- TODO need to pass errors
|
||||||
( Nothing, Dict.empty )
|
( Nothing, firstFoundErrors |> Maybe.withDefault [] |> Dict.fromList )
|
||||||
|
|
||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
|
@ -70,16 +70,9 @@ all =
|
|||||||
)
|
)
|
||||||
, describe "oneOf" <|
|
, describe "oneOf" <|
|
||||||
let
|
let
|
||||||
|
oneOfParsers : Form.ServerForms String Action
|
||||||
oneOfParsers =
|
oneOfParsers =
|
||||||
Form.init
|
Form.initCombined SetQuantity
|
||||||
(\_ ->
|
|
||||||
{ combine = Validation.succeed ()
|
|
||||||
, view = \_ -> Div
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|> Form.hiddenField "kind" (Field.exactValue "signout" "Expected signout")
|
|
||||||
|> Form.initCombined (\() -> Signout)
|
|
||||||
|> Form.combine SetQuantity
|
|
||||||
(Form.init
|
(Form.init
|
||||||
(\_ uuid quantity ->
|
(\_ uuid quantity ->
|
||||||
{ combine =
|
{ combine =
|
||||||
@ -94,6 +87,15 @@ all =
|
|||||||
|> Form.hiddenField "uuid" (Field.text |> Field.required "Required")
|
|> Form.hiddenField "uuid" (Field.text |> Field.required "Required")
|
||||||
|> Form.field "quantity" (Field.int { invalid = \_ -> "Expected int" } |> Field.required "Required")
|
|> Form.field "quantity" (Field.int { invalid = \_ -> "Expected int" } |> Field.required "Required")
|
||||||
)
|
)
|
||||||
|
|> Form.combine (\() -> Signout)
|
||||||
|
(Form.init
|
||||||
|
(\_ ->
|
||||||
|
{ combine = Validation.succeed ()
|
||||||
|
, view = \_ -> Div
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|> Form.hiddenField "kind" (Field.exactValue "signout" "Expected signout")
|
||||||
|
)
|
||||||
in
|
in
|
||||||
[ test "first branch" <|
|
[ test "first branch" <|
|
||||||
\() ->
|
\() ->
|
||||||
|
Loading…
Reference in New Issue
Block a user