mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 14:15:33 +03:00
Rename types.
This commit is contained in:
parent
f84be86bcc
commit
f1f25f787e
@ -7,7 +7,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (Validation)
|
||||
import Form.Validation as Validation exposing (Combined)
|
||||
import Form.Value
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
|
@ -6,7 +6,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html exposing (Html)
|
||||
@ -136,7 +136,7 @@ form =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
Html.div []
|
||||
@ -148,7 +148,7 @@ fieldView formState label field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|
@ -7,7 +7,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Form.Value
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
@ -126,7 +126,7 @@ init maybePageUrl sharedModel static =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
Html.div []
|
||||
@ -138,7 +138,7 @@ fieldView formState label field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|
@ -11,7 +11,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Form.Value
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
@ -831,7 +831,7 @@ textInput info labelText field =
|
||||
]
|
||||
|
||||
|
||||
errorsView : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsView : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsView formState field =
|
||||
let
|
||||
showErrors : Bool
|
||||
|
@ -13,7 +13,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Form.Value
|
||||
import FormDecoder exposing (FormData)
|
||||
import Graphql.Operation exposing (RootMutation, RootQuery)
|
||||
@ -230,7 +230,7 @@ createForm =
|
||||
|
||||
descriptionFieldView :
|
||||
Form.Context String data
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
descriptionFieldView formState field =
|
||||
Html.div []
|
||||
@ -242,7 +242,7 @@ descriptionFieldView formState field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|
@ -7,7 +7,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import GroupName exposing (GroupName)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
@ -244,7 +244,7 @@ postForm =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
Html.div []
|
||||
@ -256,7 +256,7 @@ fieldView formState label field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsForField formState field =
|
||||
(if formState.submitAttempted then
|
||||
formState.errors
|
||||
|
@ -6,7 +6,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
@ -248,7 +248,7 @@ dependentParser =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
let
|
||||
|
@ -6,7 +6,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html exposing (Html)
|
||||
@ -116,7 +116,7 @@ form =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
Html.div []
|
||||
@ -128,7 +128,7 @@ fieldView formState label field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> FieldValidation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> Field String parsed kind -> Html msg
|
||||
errorsForField formState field =
|
||||
(if formState.submitAttempted then
|
||||
formState.errors
|
||||
|
@ -7,7 +7,7 @@ import ErrorPage exposing (ErrorPage)
|
||||
import Form
|
||||
import Form.Field as Field
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
@ -175,7 +175,7 @@ dependentParser =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Field String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
let
|
||||
|
94
src/Form.elm
94
src/Form.elm
@ -80,7 +80,7 @@ import Dict exposing (Dict)
|
||||
import Dict.Extra
|
||||
import Form.Field as Field exposing (Field(..))
|
||||
import Form.FieldView
|
||||
import Form.Validation as Validation exposing (AnyValidation, FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Validation)
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import Html.Lazy
|
||||
@ -89,7 +89,7 @@ import Html.Styled.Attributes as StyledAttr
|
||||
import Html.Styled.Lazy
|
||||
import Json.Encode as Encode
|
||||
import Pages.FormState as Form exposing (FormState)
|
||||
import Pages.Internal.Form exposing (AnyValidation(..))
|
||||
import Pages.Internal.Form exposing (Validation(..))
|
||||
import Pages.Msg
|
||||
import Pages.Transition
|
||||
|
||||
@ -146,7 +146,7 @@ dynamic :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : AnyValidation error parsed named constraints1
|
||||
{ combine : Validation error parsed named constraints1
|
||||
, view : subView
|
||||
}
|
||||
data
|
||||
@ -155,7 +155,7 @@ dynamic :
|
||||
Form
|
||||
error
|
||||
--((decider -> Validation error parsed named) -> combined)
|
||||
({ combine : decider -> AnyValidation error parsed named constraints1
|
||||
({ combine : decider -> Validation error parsed named constraints1
|
||||
, view : decider -> subView
|
||||
}
|
||||
-> parsedAndView
|
||||
@ -174,7 +174,7 @@ dynamic forms formBuilder =
|
||||
decider
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { combine : AnyValidation error parsed named constraints1, view : subView }
|
||||
, parsedAndView : { combine : Validation error parsed named constraints1, view : subView }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
toParser decider =
|
||||
@ -192,7 +192,7 @@ dynamic forms formBuilder =
|
||||
let
|
||||
newThing :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { combine : decider -> AnyValidation error parsed named constraints1, view : decider -> subView } -> parsedAndView
|
||||
, parsedAndView : { combine : decider -> Validation error parsed named constraints1, view : decider -> subView } -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
newThing =
|
||||
@ -200,7 +200,7 @@ dynamic forms formBuilder =
|
||||
Form _ parseFn _ ->
|
||||
parseFn maybeData formState
|
||||
|
||||
arg : { combine : decider -> AnyValidation error parsed named constraints1, view : decider -> subView }
|
||||
arg : { combine : decider -> Validation error parsed named constraints1, view : decider -> subView }
|
||||
arg =
|
||||
{ combine =
|
||||
toParser
|
||||
@ -312,7 +312,7 @@ andThen andThenFn ( maybe, fieldErrors ) =
|
||||
field :
|
||||
String
|
||||
-> Field error parsed data kind constraints
|
||||
-> Form error (FieldValidation error parsed kind -> parsedAndView) data
|
||||
-> Form error (Validation.Field error parsed kind -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
||||
Form
|
||||
@ -339,13 +339,13 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
||||
, kind = ( kind, fieldParser.properties )
|
||||
}
|
||||
|
||||
parsedField : FieldValidation error parsed kind
|
||||
parsedField : Validation.Field error parsed kind
|
||||
parsedField =
|
||||
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
||||
|
||||
myFn :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : FieldValidation error parsed kind -> parsedAndView
|
||||
, parsedAndView : Validation.Field error parsed kind -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
->
|
||||
@ -360,7 +360,7 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
||||
fieldParser.serverValidation rawFieldValue
|
||||
|> DataSource.map (Tuple.pair name)
|
||||
|
||||
validationField : FieldValidation error parsed kind
|
||||
validationField : Validation.Field error parsed kind
|
||||
validationField =
|
||||
parsedField
|
||||
in
|
||||
@ -394,7 +394,7 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
||||
hiddenField :
|
||||
String
|
||||
-> Field error parsed data kind constraints
|
||||
-> Form error (FieldValidation error parsed Form.FieldView.Hidden -> parsedAndView) data
|
||||
-> Form error (Validation.Field error parsed Form.FieldView.Hidden -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues) =
|
||||
Form
|
||||
@ -421,13 +421,13 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
||||
, kind = ( Form.FieldView.Hidden, fieldParser.properties )
|
||||
}
|
||||
|
||||
parsedField : FieldValidation error parsed Form.FieldView.Hidden
|
||||
parsedField : Validation.Field error parsed Form.FieldView.Hidden
|
||||
parsedField =
|
||||
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
||||
|
||||
myFn :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : FieldValidation error parsed Form.FieldView.Hidden -> parsedAndView
|
||||
, parsedAndView : Validation.Field error parsed Form.FieldView.Hidden -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
->
|
||||
@ -442,7 +442,7 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
||||
fieldParser.serverValidation rawFieldValue
|
||||
|> DataSource.map (Tuple.pair name)
|
||||
|
||||
validationField : FieldValidation error parsed Form.FieldView.Hidden
|
||||
validationField : Validation.Field error parsed Form.FieldView.Hidden
|
||||
validationField =
|
||||
parsedField
|
||||
in
|
||||
@ -549,7 +549,7 @@ type Errors error
|
||||
|
||||
|
||||
{-| -}
|
||||
errorsForField : FieldValidation error parsed kind -> Errors error -> List error
|
||||
errorsForField : Validation.Field error parsed kind -> Errors error -> List error
|
||||
errorsForField field_ (Errors errorsDict) =
|
||||
errorsDict
|
||||
|> Dict.get (Validation.fieldName field_)
|
||||
@ -578,8 +578,8 @@ type alias AppContext app =
|
||||
|
||||
|
||||
mergeResults :
|
||||
{ a | result : ( AnyValidation error parsed named constraints1, Dict String (List error) ) }
|
||||
-> AnyValidation error parsed unnamed constraints2
|
||||
{ a | result : ( Validation error parsed named constraints1, Dict String (List error) ) }
|
||||
-> Validation error parsed unnamed constraints2
|
||||
mergeResults parsed =
|
||||
case parsed.result of
|
||||
( Pages.Internal.Form.Validation viewField name ( parsedThing, combineErrors ), individualFieldErrors ) ->
|
||||
@ -592,7 +592,7 @@ mergeResults parsed =
|
||||
|
||||
mergeResultsDataSource :
|
||||
{ a
|
||||
| result : ( AnyValidation error parsed named constraints, FieldErrors error )
|
||||
| result : ( Validation error parsed named constraints, FieldErrors error )
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
@ -668,7 +668,7 @@ parse :
|
||||
String
|
||||
-> AppContext app
|
||||
-> data
|
||||
-> Form error { info | combine : AnyValidation error parsed named constraints } data
|
||||
-> Form error { info | combine : Validation error parsed named constraints } data
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
parse formId app data (Form _ parser _) =
|
||||
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
||||
@ -676,7 +676,7 @@ parse formId app data (Form _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { info | combine : AnyValidation error parsed named constraints }
|
||||
, parsedAndView : { info | combine : Validation error parsed named constraints }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
@ -708,13 +708,13 @@ insertIfNonempty key values dict =
|
||||
{-| -}
|
||||
runServerSide :
|
||||
List ( String, String )
|
||||
-> Form error { all | combine : AnyValidation error parsed kind constraints } data
|
||||
-> Form error { all | combine : Validation error parsed kind constraints } data
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
runServerSide rawFormData (Form _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { all | combine : AnyValidation error parsed kind constraints }
|
||||
, parsedAndView : { all | combine : Validation error parsed kind constraints }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
@ -745,13 +745,13 @@ runServerSide rawFormData (Form _ parser _) =
|
||||
{-| -}
|
||||
runServerSideWithoutServerValidations :
|
||||
List ( String, String )
|
||||
-> Form error { all | combine : AnyValidation error parsed kind constraints } data
|
||||
-> Form error { all | combine : Validation error parsed kind constraints } data
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
runServerSideWithoutServerValidations rawFormData (Form _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { all | combine : AnyValidation error parsed kind constraints }
|
||||
, parsedAndView : { all | combine : Validation error parsed kind constraints }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
@ -780,7 +780,7 @@ runServerSideWithoutServerValidations rawFormData (Form _ parser _) =
|
||||
|> unwrapValidation
|
||||
|
||||
|
||||
unwrapValidation : AnyValidation error parsed named constraints -> ( Maybe parsed, FieldErrors error )
|
||||
unwrapValidation : Validation error parsed named constraints -> ( Maybe parsed, FieldErrors error )
|
||||
unwrapValidation (Pages.Internal.Form.Validation viewField name ( maybeParsed, errors )) =
|
||||
( maybeParsed, errors )
|
||||
|
||||
@ -792,7 +792,7 @@ runOneOfServerSide :
|
||||
List
|
||||
(Form
|
||||
error
|
||||
{ all | combine : AnyValidation error parsed kind constraints }
|
||||
{ all | combine : Validation error parsed kind constraints }
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
@ -829,7 +829,7 @@ runOneOfServerSideWithServerValidations :
|
||||
List
|
||||
(Form
|
||||
error
|
||||
{ all | combine : AnyValidation error parsed kind constraints }
|
||||
{ all | combine : Validation error parsed kind constraints }
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
@ -867,7 +867,7 @@ renderHtml :
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(AnyValidation error parsed named constraints)
|
||||
(Validation error parsed named constraints)
|
||||
data
|
||||
(Context error data
|
||||
-> List (Html (Pages.Msg.Msg msg))
|
||||
@ -917,14 +917,14 @@ toDynamicFetcher :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
data
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(AnyValidation error parsed field constraints)
|
||||
(Validation error parsed field constraints)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicFetcher name (Form a b c) =
|
||||
@ -941,7 +941,7 @@ toDynamicFetcher name (Form a b c) =
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -952,7 +952,7 @@ toDynamicFetcher name (Form a b c) =
|
||||
-> Form.FormState
|
||||
->
|
||||
{ result :
|
||||
( AnyValidation error parsed field constraints
|
||||
( Validation error parsed field constraints
|
||||
, Dict String (List error)
|
||||
)
|
||||
, view : Context error data -> view
|
||||
@ -965,7 +965,7 @@ toDynamicFetcher name (Form a b c) =
|
||||
foo :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -987,14 +987,14 @@ toDynamicTransition :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
data
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(AnyValidation error parsed field constraints)
|
||||
(Validation error parsed field constraints)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicTransition name (Form a b c) =
|
||||
@ -1011,7 +1011,7 @@ toDynamicTransition name (Form a b c) =
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -1022,7 +1022,7 @@ toDynamicTransition name (Form a b c) =
|
||||
-> Form.FormState
|
||||
->
|
||||
{ result :
|
||||
( AnyValidation error parsed field constraints
|
||||
( Validation error parsed field constraints
|
||||
, Dict String (List error)
|
||||
)
|
||||
, view : Context error data -> view
|
||||
@ -1035,7 +1035,7 @@ toDynamicTransition name (Form a b c) =
|
||||
foo :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : AnyValidation error parsed field constraints
|
||||
{ combine : Validation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -1070,7 +1070,7 @@ renderStyledHtml :
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(AnyValidation error parsed named constraints)
|
||||
(Validation error parsed named constraints)
|
||||
data
|
||||
(Context error data
|
||||
-> List (Html.Styled.Html (Pages.Msg.Msg msg))
|
||||
@ -1090,7 +1090,7 @@ renderHelper :
|
||||
-> RenderOptions
|
||||
-> AppContext app
|
||||
-> data
|
||||
-> FormInternal error (AnyValidation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
||||
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
||||
-> Html (Pages.Msg.Msg msg)
|
||||
renderHelper attrs maybe options formState data ((FormInternal fieldDefinitions parser toInitialValues) as form) =
|
||||
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
||||
@ -1129,7 +1129,7 @@ renderStyledHelper :
|
||||
-> RenderOptions
|
||||
-> AppContext app
|
||||
-> data
|
||||
-> FormInternal error (AnyValidation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
||||
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
||||
-> Html.Styled.Html (Pages.Msg.Msg msg)
|
||||
renderStyledHelper attrs maybe options formState data ((FormInternal fieldDefinitions parser toInitialValues) as form) =
|
||||
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
||||
@ -1171,7 +1171,7 @@ helperValues :
|
||||
-> AppContext app
|
||||
-> data
|
||||
---> Form error parsed data view
|
||||
-> FormInternal error (AnyValidation error parsed named constraints) data (Context error data -> List view)
|
||||
-> FormInternal error (Validation error parsed named constraints) data (Context error data -> List view)
|
||||
-> { formId : String, hiddenInputs : List view, children : List view, isValid : Bool }
|
||||
helperValues toHiddenInput maybe options formState data (FormInternal fieldDefinitions parser toInitialValues) =
|
||||
let
|
||||
@ -1210,14 +1210,14 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
||||
|> Dict.union part2
|
||||
|
||||
parsed :
|
||||
{ result : ( AnyValidation error parsed named constraints, Dict String (List error) )
|
||||
{ result : ( Validation error parsed named constraints, Dict String (List error) )
|
||||
, view : Context error data -> List view
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
parser (Just data) thisFormState
|
||||
|
||||
merged : AnyValidation error parsed named constraints
|
||||
merged : Validation error parsed named constraints
|
||||
merged =
|
||||
mergeResults
|
||||
{ parsed
|
||||
@ -1344,7 +1344,7 @@ toResult ( maybeParsed, fieldErrors ) =
|
||||
type alias HtmlForm error parsed data msg =
|
||||
Form
|
||||
error
|
||||
{ combine : Validation.Validation error parsed
|
||||
{ combine : Validation.Combined error parsed
|
||||
, view : Context error data -> List (Html (Pages.Msg.Msg msg))
|
||||
}
|
||||
data
|
||||
@ -1354,7 +1354,7 @@ type alias HtmlForm error parsed data msg =
|
||||
type alias StyledHtmlForm error parsed data msg =
|
||||
Form
|
||||
error
|
||||
{ combine : Validation error parsed
|
||||
{ combine : Combined error parsed
|
||||
, view : Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg))
|
||||
}
|
||||
data
|
||||
|
@ -26,7 +26,7 @@ import Html.Attributes as Attr
|
||||
import Html.Styled
|
||||
import Html.Styled.Attributes as StyledAttr
|
||||
import Json.Encode as Encode
|
||||
import Pages.Internal.Form exposing (AnyValidation(..), ViewField)
|
||||
import Pages.Internal.Form exposing (Validation(..), ViewField)
|
||||
|
||||
|
||||
{-| -}
|
||||
@ -112,7 +112,7 @@ type Options a
|
||||
{-| -}
|
||||
input :
|
||||
List (Html.Attribute msg)
|
||||
-> Form.Validation.FieldValidation error parsed Input
|
||||
-> Form.Validation.Field error parsed Input
|
||||
-> Html msg
|
||||
input attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -158,7 +158,7 @@ input attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
{-| -}
|
||||
inputStyled :
|
||||
List (Html.Styled.Attribute msg)
|
||||
-> Form.Validation.FieldValidation error parsed Input
|
||||
-> Form.Validation.Field error parsed Input
|
||||
-> Html.Styled.Html msg
|
||||
inputStyled attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -265,7 +265,7 @@ radio :
|
||||
-> (List (Html.Attribute msg) -> Html msg)
|
||||
-> Html msg
|
||||
)
|
||||
-> Form.Validation.FieldValidation error parsed2 (Options parsed)
|
||||
-> Form.Validation.Field error parsed2 (Options parsed)
|
||||
-> Html msg
|
||||
radio selectAttrs enumToOption (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -340,7 +340,7 @@ radioStyled :
|
||||
-> (List (Html.Styled.Attribute msg) -> Html.Styled.Html msg)
|
||||
-> Html.Styled.Html msg
|
||||
)
|
||||
-> Form.Validation.FieldValidation error parsed2 (Options parsed)
|
||||
-> Form.Validation.Field error parsed2 (Options parsed)
|
||||
-> Html.Styled.Html msg
|
||||
radioStyled selectAttrs enumToOption (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Form.Validation exposing
|
||||
( Validation, FieldValidation, AnyValidation
|
||||
( Combined, Field, Validation
|
||||
, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
, value, fieldName
|
||||
)
|
||||
@ -9,7 +9,7 @@ module Form.Validation exposing
|
||||
|
||||
## Validations
|
||||
|
||||
@docs Validation, FieldValidation, AnyValidation
|
||||
@docs Combined, Field, Validation
|
||||
|
||||
@docs andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
|
||||
@ -21,39 +21,39 @@ module Form.Validation exposing
|
||||
-}
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Pages.Internal.Form exposing (AnyValidation(..))
|
||||
import Pages.Internal.Form exposing (Validation(..))
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias Validation error parsed =
|
||||
Pages.Internal.Form.AnyValidation error parsed Never Never
|
||||
type alias Combined error parsed =
|
||||
Pages.Internal.Form.Validation error parsed Never Never
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias FieldValidation error parsed kind =
|
||||
Pages.Internal.Form.AnyValidation error parsed kind { field : kind }
|
||||
type alias Field error parsed kind =
|
||||
Pages.Internal.Form.Validation error parsed kind { field : kind }
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias AnyValidation error parsed kind constraints =
|
||||
Pages.Internal.Form.AnyValidation error parsed kind constraints
|
||||
type alias Validation error parsed kind constraints =
|
||||
Pages.Internal.Form.Validation error parsed kind constraints
|
||||
|
||||
|
||||
{-| -}
|
||||
fieldName : FieldValidation error parsed kind -> String
|
||||
fieldName : Field error parsed kind -> String
|
||||
fieldName (Validation viewField name ( maybeParsed, errors )) =
|
||||
name
|
||||
|> Maybe.withDefault ""
|
||||
|
||||
|
||||
{-| -}
|
||||
succeed : parsed -> Validation error parsed
|
||||
succeed : parsed -> Combined error parsed
|
||||
succeed parsed =
|
||||
Validation Nothing Nothing ( Just parsed, Dict.empty )
|
||||
|
||||
|
||||
{-| -}
|
||||
withFallback : parsed -> AnyValidation error parsed named constraints -> AnyValidation error parsed named constraints
|
||||
withFallback : parsed -> Validation error parsed named constraints -> Validation error parsed named constraints
|
||||
withFallback parsed (Validation viewField name ( maybeParsed, errors )) =
|
||||
Validation viewField
|
||||
name
|
||||
@ -65,33 +65,33 @@ withFallback parsed (Validation viewField name ( maybeParsed, errors )) =
|
||||
|
||||
|
||||
{-| -}
|
||||
value : AnyValidation error parsed named constraint -> Maybe parsed
|
||||
value : Validation error parsed named constraint -> Maybe parsed
|
||||
value (Validation _ _ ( maybeParsed, _ )) =
|
||||
maybeParsed
|
||||
|
||||
|
||||
{-| -}
|
||||
parseWithError : parsed -> ( String, error ) -> Validation error parsed
|
||||
parseWithError : parsed -> ( String, error ) -> Combined error parsed
|
||||
parseWithError parsed ( key, error ) =
|
||||
Validation Nothing Nothing ( Just parsed, Dict.singleton key [ error ] )
|
||||
|
||||
|
||||
{-| -}
|
||||
fail : FieldValidation error parsed1 field -> error -> Validation error parsed
|
||||
fail : Field error parsed1 field -> error -> Combined error parsed
|
||||
fail (Validation _ key _) parsed =
|
||||
-- TODO need to prevent Never fields from being used
|
||||
Validation Nothing Nothing ( Nothing, Dict.singleton (key |> Maybe.withDefault "") [ parsed ] )
|
||||
|
||||
|
||||
{-| -}
|
||||
withError : FieldValidation error parsed1 field -> error -> AnyValidation error parsed2 named constraints -> AnyValidation error parsed2 named constraints
|
||||
withError : Field error parsed1 field -> error -> Validation error parsed2 named constraints -> Validation error parsed2 named constraints
|
||||
withError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
|
||||
-- TODO need to prevent Never fields from being used
|
||||
Validation viewField name ( maybeParsedA, errorsA |> insertIfNonempty (key |> Maybe.withDefault "") [ error ] )
|
||||
|
||||
|
||||
{-| -}
|
||||
withErrorIf : Bool -> FieldValidation error ignored field -> error -> AnyValidation error parsed named constraints -> AnyValidation error parsed named constraints
|
||||
withErrorIf : Bool -> Field error ignored field -> error -> Validation error parsed named constraints -> Validation error parsed named constraints
|
||||
withErrorIf includeError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
|
||||
-- TODO use something like { field : kind } for type variable to check that it represents a field
|
||||
Validation viewField
|
||||
@ -110,13 +110,13 @@ withErrorIf includeError (Validation _ key _) error (Validation viewField name (
|
||||
|
||||
|
||||
{-| -}
|
||||
map : (parsed -> mapped) -> AnyValidation error parsed named constraint -> Validation error mapped
|
||||
map : (parsed -> mapped) -> Validation error parsed named constraint -> Combined error mapped
|
||||
map mapFn (Validation viewField name ( maybeParsedA, errorsA )) =
|
||||
Validation Nothing name ( Maybe.map mapFn maybeParsedA, errorsA )
|
||||
|
||||
|
||||
{-| -}
|
||||
fromResult : Result ( String, error ) parsed -> Validation error parsed
|
||||
fromResult : Result ( String, error ) parsed -> Combined error parsed
|
||||
fromResult result =
|
||||
case result of
|
||||
Ok parsed ->
|
||||
@ -127,13 +127,13 @@ fromResult result =
|
||||
|
||||
|
||||
{-| -}
|
||||
andMap : AnyValidation error a named1 constraints1 -> AnyValidation error (a -> b) named2 constraints2 -> Validation error b
|
||||
andMap : Validation error a named1 constraints1 -> Validation error (a -> b) named2 constraints2 -> Combined error b
|
||||
andMap =
|
||||
map2 (|>)
|
||||
|
||||
|
||||
{-| -}
|
||||
andThen : (parsed -> AnyValidation error mapped named1 constraints1) -> AnyValidation error parsed named2 constraints2 -> Validation error mapped
|
||||
andThen : (parsed -> Validation error mapped named1 constraints1) -> Validation error parsed named2 constraints2 -> Combined error mapped
|
||||
andThen andThenFn (Validation _ name ( maybeParsed, errors )) =
|
||||
case maybeParsed of
|
||||
Just parsed ->
|
||||
@ -147,7 +147,7 @@ andThen andThenFn (Validation _ name ( maybeParsed, errors )) =
|
||||
|
||||
|
||||
{-| -}
|
||||
map2 : (a -> b -> c) -> AnyValidation error a named1 constraints1 -> AnyValidation error b named2 constraints2 -> Validation error c
|
||||
map2 : (a -> b -> c) -> Validation error a named1 constraints1 -> Validation error b named2 constraints2 -> Combined error c
|
||||
map2 f (Validation _ name1 ( maybeParsedA, errorsA )) (Validation _ name2 ( maybeParsedB, errorsB )) =
|
||||
Validation Nothing
|
||||
Nothing
|
||||
@ -157,7 +157,7 @@ map2 f (Validation _ name1 ( maybeParsedA, errorsA )) (Validation _ name2 ( mayb
|
||||
|
||||
|
||||
{-| -}
|
||||
fromMaybe : Maybe parsed -> Validation error parsed
|
||||
fromMaybe : Maybe parsed -> Combined error parsed
|
||||
fromMaybe maybe =
|
||||
Validation Nothing Nothing ( maybe, Dict.empty )
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
module Pages.Internal.Form exposing (AnyValidation(..), ViewField)
|
||||
module Pages.Internal.Form exposing (Validation(..), ViewField)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Encode as Encode
|
||||
import Pages.FormState
|
||||
|
||||
|
||||
type AnyValidation error parsed kind field
|
||||
type Validation error parsed kind field
|
||||
= Validation (Maybe (ViewField kind)) (Maybe String) ( Maybe parsed, Dict String (List error) )
|
||||
|
||||
|
||||
|
@ -90,7 +90,7 @@ import CookieParser
|
||||
import DataSource exposing (DataSource)
|
||||
import Dict exposing (Dict)
|
||||
import Form
|
||||
import Form.Validation as Validation exposing (AnyValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Validation)
|
||||
import FormData
|
||||
import Internal.Request
|
||||
import Json.Decode
|
||||
@ -887,7 +887,7 @@ formDataWithoutServerValidation :
|
||||
List
|
||||
(Form.Form
|
||||
error
|
||||
{ all | combine : AnyValidation error combined kind constraints }
|
||||
{ all | combine : Validation error combined kind constraints }
|
||||
data
|
||||
)
|
||||
-> Parser (Result { fields : List ( String, String ), errors : Dict String (List error) } combined)
|
||||
@ -923,7 +923,7 @@ formData :
|
||||
List
|
||||
(Form.Form
|
||||
error
|
||||
{ all | combine : AnyValidation error combined kind constraints }
|
||||
{ all | combine : Validation error combined kind constraints }
|
||||
data
|
||||
)
|
||||
-> Parser (DataSource (Result { fields : List ( String, String ), errors : Dict String (List error) } combined))
|
||||
|
@ -5,7 +5,7 @@ import Dict
|
||||
import Expect
|
||||
import Form exposing (Form)
|
||||
import Form.Field as Field
|
||||
import Form.Validation as Validation exposing (AnyValidation, FieldValidation, Validation)
|
||||
import Form.Validation as Validation exposing (Combined, Field, Validation)
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ all =
|
||||
checkinFormParser :
|
||||
Form
|
||||
String
|
||||
{ combine : Validation String ( Date, Date ), view : a -> MyView }
|
||||
{ combine : Combined String ( Date, Date ), view : a -> MyView }
|
||||
data
|
||||
checkinFormParser =
|
||||
Form.init
|
||||
@ -272,7 +272,7 @@ all =
|
||||
]
|
||||
, describe "dependent parsing" <|
|
||||
let
|
||||
linkForm : Form String { combine : Validation String PostAction, view : Form.Context String data -> MyView } data
|
||||
linkForm : Form String { combine : Combined String PostAction, view : Form.Context String data -> MyView } data
|
||||
linkForm =
|
||||
Form.init
|
||||
(\url ->
|
||||
@ -289,7 +289,7 @@ all =
|
||||
|> Field.url
|
||||
)
|
||||
|
||||
postForm : Form String { combine : Validation String PostAction, view : Form.Context String data -> MyView } data
|
||||
postForm : Form String { combine : Combined String PostAction, view : Form.Context String data -> MyView } data
|
||||
postForm =
|
||||
Form.init
|
||||
(\title body ->
|
||||
@ -309,7 +309,7 @@ all =
|
||||
|> Form.field "title" (Field.text |> Field.required "Required")
|
||||
|> Form.field "body" Field.text
|
||||
|
||||
dependentParser : Form String { combine : Validation String PostAction, view : Form.Context String data -> MyView } data
|
||||
dependentParser : Form String { combine : Combined String PostAction, view : Form.Context String data -> MyView } data
|
||||
dependentParser =
|
||||
Form.init
|
||||
(\kind postForm_ ->
|
||||
|
Loading…
Reference in New Issue
Block a user