mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 14:15:33 +03:00
Change Validation type to support constraints for named fields with new design.
This commit is contained in:
parent
8154ad1e14
commit
ea22871b65
@ -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 (OnlyValidation)
|
||||
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 (Validation)
|
||||
import Form.Validation as Validation exposing (OnlyValidation)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html exposing (Html)
|
||||
@ -136,7 +136,7 @@ form =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> OnlyValidation 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 -> Validation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> OnlyValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (OnlyValidation)
|
||||
import Form.Value
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
@ -126,7 +126,7 @@ init maybePageUrl sharedModel static =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> OnlyValidation 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 -> Validation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> OnlyValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (OnlyValidation)
|
||||
import Form.Value
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
@ -831,7 +831,7 @@ textInput info labelText field =
|
||||
]
|
||||
|
||||
|
||||
errorsView : Form.Context String data -> Validation String parsed kind -> Html msg
|
||||
errorsView : Form.Context String data -> OnlyValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (OnlyValidation)
|
||||
import Form.Value
|
||||
import FormDecoder exposing (FormData)
|
||||
import Graphql.Operation exposing (RootMutation, RootQuery)
|
||||
@ -230,7 +230,7 @@ createForm =
|
||||
|
||||
descriptionFieldView :
|
||||
Form.Context String data
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> OnlyValidation String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
descriptionFieldView formState field =
|
||||
Html.div []
|
||||
@ -242,7 +242,7 @@ descriptionFieldView formState field =
|
||||
]
|
||||
|
||||
|
||||
errorsForField : Form.Context String data -> Validation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> OnlyValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (FieldValidation, OnlyValidation)
|
||||
import GroupName exposing (GroupName)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
@ -244,7 +244,7 @@ postForm =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> FieldValidation 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 -> Validation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> FieldValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (FieldValidation, OnlyValidation)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
@ -248,7 +248,7 @@ dependentParser =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> FieldValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (FieldValidation, OnlyValidation)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html exposing (Html)
|
||||
@ -116,7 +116,7 @@ form =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> FieldValidation 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 -> Validation String parsed kind -> Html msg
|
||||
errorsForField : Form.Context String data -> FieldValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (FieldValidation, OnlyValidation)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
@ -175,7 +175,7 @@ dependentParser =
|
||||
fieldView :
|
||||
Form.Context String data
|
||||
-> String
|
||||
-> Validation String parsed Form.FieldView.Input
|
||||
-> FieldValidation String parsed Form.FieldView.Input
|
||||
-> Html msg
|
||||
fieldView formState label field =
|
||||
let
|
||||
|
92
src/Form.elm
92
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 (Validation)
|
||||
import Form.Validation as Validation exposing (FieldValidation, LowLevelValidation, OnlyValidation)
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import Html.Lazy
|
||||
@ -146,7 +146,7 @@ dynamic :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : Validation error parsed named
|
||||
{ combine : LowLevelValidation error parsed named constraints1
|
||||
, view : subView
|
||||
}
|
||||
data
|
||||
@ -155,7 +155,7 @@ dynamic :
|
||||
Form
|
||||
error
|
||||
--((decider -> Validation error parsed named) -> combined)
|
||||
({ combine : decider -> Validation error parsed named
|
||||
({ combine : decider -> LowLevelValidation error parsed named constraints1
|
||||
, view : decider -> subView
|
||||
}
|
||||
-> parsedAndView
|
||||
@ -174,7 +174,7 @@ dynamic forms formBuilder =
|
||||
decider
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { combine : Validation error parsed named, view : subView }
|
||||
, parsedAndView : { combine : LowLevelValidation 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 -> Validation error parsed named, view : decider -> subView } -> parsedAndView
|
||||
, parsedAndView : { combine : decider -> LowLevelValidation error parsed named constraints1, view : decider -> subView } -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
newThing =
|
||||
@ -200,7 +200,7 @@ dynamic forms formBuilder =
|
||||
FormNew _ parseFn _ ->
|
||||
parseFn maybeData formState
|
||||
|
||||
arg : { combine : decider -> Validation error parsed named, view : decider -> subView }
|
||||
arg : { combine : decider -> LowLevelValidation 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 (Validation error parsed kind -> parsedAndView) data
|
||||
-> Form error (FieldValidation error parsed kind -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
field name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues) =
|
||||
FormNew
|
||||
@ -339,13 +339,13 @@ field name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues
|
||||
, kind = ( kind, fieldParser.properties )
|
||||
}
|
||||
|
||||
parsedField : Validation error parsed kind
|
||||
parsedField : FieldValidation error parsed kind
|
||||
parsedField =
|
||||
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
||||
|
||||
myFn :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : Validation error parsed kind -> parsedAndView
|
||||
, parsedAndView : FieldValidation error parsed kind -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
->
|
||||
@ -360,7 +360,7 @@ field name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues
|
||||
fieldParser.serverValidation rawFieldValue
|
||||
|> DataSource.map (Tuple.pair name)
|
||||
|
||||
validationField : Validation error parsed kind
|
||||
validationField : FieldValidation error parsed kind
|
||||
validationField =
|
||||
parsedField
|
||||
in
|
||||
@ -394,7 +394,7 @@ field name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues
|
||||
hiddenField :
|
||||
String
|
||||
-> Field error parsed data kind constraints
|
||||
-> Form error (Validation error parsed Form.FieldView.Hidden -> parsedAndView) data
|
||||
-> Form error (FieldValidation error parsed Form.FieldView.Hidden -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
hiddenField name (Field fieldParser _) (FormNew definitions parseFn toInitialValues) =
|
||||
FormNew
|
||||
@ -421,13 +421,13 @@ hiddenField name (Field fieldParser _) (FormNew definitions parseFn toInitialVal
|
||||
, kind = ( Form.FieldView.Hidden, fieldParser.properties )
|
||||
}
|
||||
|
||||
parsedField : Validation error parsed Form.FieldView.Hidden
|
||||
parsedField : FieldValidation error parsed Form.FieldView.Hidden
|
||||
parsedField =
|
||||
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
||||
|
||||
myFn :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : Validation error parsed Form.FieldView.Hidden -> parsedAndView
|
||||
, parsedAndView : FieldValidation error parsed Form.FieldView.Hidden -> parsedAndView
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
->
|
||||
@ -442,7 +442,7 @@ hiddenField name (Field fieldParser _) (FormNew definitions parseFn toInitialVal
|
||||
fieldParser.serverValidation rawFieldValue
|
||||
|> DataSource.map (Tuple.pair name)
|
||||
|
||||
validationField : Validation error parsed Form.FieldView.Hidden
|
||||
validationField : FieldValidation error parsed Form.FieldView.Hidden
|
||||
validationField =
|
||||
parsedField
|
||||
in
|
||||
@ -549,7 +549,7 @@ type Errors error
|
||||
|
||||
|
||||
{-| -}
|
||||
errorsForField : Validation error parsed kind -> Errors error -> List error
|
||||
errorsForField : FieldValidation 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 : ( Validation error parsed named, Dict String (List error) ) }
|
||||
-> Validation error parsed unnamed
|
||||
{ a | result : ( LowLevelValidation error parsed named constraints1, Dict String (List error) ) }
|
||||
-> LowLevelValidation 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 : ( Validation error parsed named, FieldErrors error )
|
||||
| result : ( LowLevelValidation 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 : Validation error parsed named } data
|
||||
-> Form error { info | combine : LowLevelValidation error parsed named constraints } data
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
parse formId app data (FormNew _ 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 (FormNew _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { info | combine : Validation error parsed named }
|
||||
, parsedAndView : { info | combine : LowLevelValidation 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 : Validation error parsed kind } data
|
||||
-> Form error { all | combine : LowLevelValidation error parsed kind constraints } data
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
runServerSide rawFormData (FormNew _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { all | combine : Validation error parsed kind }
|
||||
, parsedAndView : { all | combine : LowLevelValidation error parsed kind constraints }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
@ -745,13 +745,13 @@ runServerSide rawFormData (FormNew _ parser _) =
|
||||
{-| -}
|
||||
runServerSideWithoutServerValidations :
|
||||
List ( String, String )
|
||||
-> Form error { all | combine : Validation error parsed kind } data
|
||||
-> Form error { all | combine : LowLevelValidation error parsed kind constraints } data
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
runServerSideWithoutServerValidations rawFormData (FormNew _ parser _) =
|
||||
let
|
||||
parsed :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView : { all | combine : Validation error parsed kind }
|
||||
, parsedAndView : { all | combine : LowLevelValidation error parsed kind constraints }
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
}
|
||||
parsed =
|
||||
@ -780,7 +780,7 @@ runServerSideWithoutServerValidations rawFormData (FormNew _ parser _) =
|
||||
|> unwrapValidation
|
||||
|
||||
|
||||
unwrapValidation : Validation error parsed named -> ( Maybe parsed, FieldErrors error )
|
||||
unwrapValidation : LowLevelValidation 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 : Validation error parsed kind }
|
||||
{ all | combine : LowLevelValidation error parsed kind constraints }
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
@ -829,7 +829,7 @@ runOneOfServerSideWithServerValidations :
|
||||
List
|
||||
(Form
|
||||
error
|
||||
{ all | combine : Validation error parsed kind }
|
||||
{ all | combine : LowLevelValidation error parsed kind constraints }
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
@ -867,7 +867,7 @@ renderHtml :
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(Validation error parsed named)
|
||||
(LowLevelValidation error parsed named constraints)
|
||||
data
|
||||
(Context error data
|
||||
-> List (Html (Pages.Msg.Msg msg))
|
||||
@ -917,14 +917,14 @@ toDynamicFetcher :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
data
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(Validation error parsed field)
|
||||
(LowLevelValidation error parsed field constraints)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicFetcher name (FormNew a b c) =
|
||||
@ -941,7 +941,7 @@ toDynamicFetcher name (FormNew a b c) =
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -952,7 +952,7 @@ toDynamicFetcher name (FormNew a b c) =
|
||||
-> Form.FormState
|
||||
->
|
||||
{ result :
|
||||
( Validation error parsed field
|
||||
( LowLevelValidation error parsed field constraints
|
||||
, Dict String (List error)
|
||||
)
|
||||
, view : Context error data -> view
|
||||
@ -965,7 +965,7 @@ toDynamicFetcher name (FormNew a b c) =
|
||||
foo :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -987,14 +987,14 @@ toDynamicTransition :
|
||||
->
|
||||
Form
|
||||
error
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
data
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(Validation error parsed field)
|
||||
(LowLevelValidation error parsed field constraints)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicTransition name (FormNew a b c) =
|
||||
@ -1011,7 +1011,7 @@ toDynamicTransition name (FormNew a b c) =
|
||||
->
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -1022,7 +1022,7 @@ toDynamicTransition name (FormNew a b c) =
|
||||
-> Form.FormState
|
||||
->
|
||||
{ result :
|
||||
( Validation error parsed field
|
||||
( LowLevelValidation error parsed field constraints
|
||||
, Dict String (List error)
|
||||
)
|
||||
, view : Context error data -> view
|
||||
@ -1035,7 +1035,7 @@ toDynamicTransition name (FormNew a b c) =
|
||||
foo :
|
||||
{ result : Dict String (List error)
|
||||
, parsedAndView :
|
||||
{ combine : Validation error parsed field
|
||||
{ combine : LowLevelValidation error parsed field constraints
|
||||
, view : Context error data -> view
|
||||
}
|
||||
, serverValidations : DataSource (List ( String, List error ))
|
||||
@ -1070,7 +1070,7 @@ renderStyledHtml :
|
||||
->
|
||||
FinalForm
|
||||
error
|
||||
(Validation error parsed named)
|
||||
(LowLevelValidation 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 (Validation error parsed named) data (Context error data -> List (Html (Pages.Msg.Msg msg)))
|
||||
-> FormInternal error (LowLevelValidation 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 (Validation error parsed named) data (Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg)))
|
||||
-> FormInternal error (LowLevelValidation 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 (Validation error parsed named) data (Context error data -> List view)
|
||||
-> FormInternal error (LowLevelValidation 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 : ( Validation error parsed named, Dict String (List error) )
|
||||
{ result : ( LowLevelValidation 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 : Validation error parsed named
|
||||
merged : LowLevelValidation 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 error parsed Never
|
||||
{ combine : Validation.OnlyValidation 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 Never
|
||||
{ combine : OnlyValidation error parsed
|
||||
, view : Context error data -> List (Html.Styled.Html (Pages.Msg.Msg msg))
|
||||
}
|
||||
data
|
||||
|
@ -20,6 +20,7 @@ module Form.FieldView exposing
|
||||
|
||||
-}
|
||||
|
||||
import Form.Validation
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import Html.Styled
|
||||
@ -111,7 +112,7 @@ type Options a
|
||||
{-| -}
|
||||
input :
|
||||
List (Html.Attribute msg)
|
||||
-> Validation error parsed Input
|
||||
-> Form.Validation.FieldValidation error parsed Input
|
||||
-> Html msg
|
||||
input attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -157,7 +158,7 @@ input attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
{-| -}
|
||||
inputStyled :
|
||||
List (Html.Styled.Attribute msg)
|
||||
-> Validation error parsed Input
|
||||
-> Form.Validation.FieldValidation error parsed Input
|
||||
-> Html.Styled.Html msg
|
||||
inputStyled attrs (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -264,7 +265,7 @@ radio :
|
||||
-> (List (Html.Attribute msg) -> Html msg)
|
||||
-> Html msg
|
||||
)
|
||||
-> Validation error parsed2 (Options parsed)
|
||||
-> Form.Validation.FieldValidation error parsed2 (Options parsed)
|
||||
-> Html msg
|
||||
radio selectAttrs enumToOption (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
@ -339,7 +340,7 @@ radioStyled :
|
||||
-> (List (Html.Styled.Attribute msg) -> Html.Styled.Html msg)
|
||||
-> Html.Styled.Html msg
|
||||
)
|
||||
-> Validation error parsed2 (Options parsed)
|
||||
-> Form.Validation.FieldValidation error parsed2 (Options parsed)
|
||||
-> Html.Styled.Html msg
|
||||
radioStyled selectAttrs enumToOption (Validation viewField fieldName ( maybeParsed, fieldErrors )) =
|
||||
let
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Form.Validation exposing
|
||||
( Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
( OnlyValidation, FieldValidation, LowLevelValidation
|
||||
, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
, value, fieldName
|
||||
)
|
||||
|
||||
@ -8,7 +9,9 @@ module Form.Validation exposing
|
||||
|
||||
## Validations
|
||||
|
||||
@docs Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
@docs OnlyValidation, FieldValidation, LowLevelValidation
|
||||
|
||||
@docs andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
|
||||
|
||||
## Field Metadata
|
||||
@ -22,25 +25,35 @@ import Pages.Internal.Form exposing (Validation(..))
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias Validation error parsed named =
|
||||
Pages.Internal.Form.Validation error parsed named
|
||||
type alias OnlyValidation error parsed =
|
||||
Pages.Internal.Form.Validation error parsed Never Never
|
||||
|
||||
|
||||
{-| -}
|
||||
fieldName : Validation error parsed kind -> String
|
||||
type alias FieldValidation error parsed kind =
|
||||
Pages.Internal.Form.Validation error parsed kind { field : kind }
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias LowLevelValidation error parsed kind constraints =
|
||||
Pages.Internal.Form.Validation error parsed kind constraints
|
||||
|
||||
|
||||
{-| -}
|
||||
fieldName : FieldValidation error parsed kind -> String
|
||||
fieldName (Validation viewField name ( maybeParsed, errors )) =
|
||||
name
|
||||
|> Maybe.withDefault ""
|
||||
|
||||
|
||||
{-| -}
|
||||
succeed : parsed -> Validation error parsed Never
|
||||
succeed : parsed -> OnlyValidation error parsed
|
||||
succeed parsed =
|
||||
Validation Nothing Nothing ( Just parsed, Dict.empty )
|
||||
|
||||
|
||||
{-| -}
|
||||
withFallback : parsed -> Validation error parsed named -> Validation error parsed named
|
||||
withFallback : parsed -> LowLevelValidation error parsed named constraints -> LowLevelValidation error parsed named constraints
|
||||
withFallback parsed (Validation viewField name ( maybeParsed, errors )) =
|
||||
Validation viewField
|
||||
name
|
||||
@ -52,33 +65,33 @@ withFallback parsed (Validation viewField name ( maybeParsed, errors )) =
|
||||
|
||||
|
||||
{-| -}
|
||||
value : Validation error parsed named -> Maybe parsed
|
||||
value : LowLevelValidation error parsed named constraint -> Maybe parsed
|
||||
value (Validation _ _ ( maybeParsed, _ )) =
|
||||
maybeParsed
|
||||
|
||||
|
||||
{-| -}
|
||||
parseWithError : parsed -> ( String, error ) -> Validation error parsed Never
|
||||
parseWithError : parsed -> ( String, error ) -> OnlyValidation error parsed
|
||||
parseWithError parsed ( key, error ) =
|
||||
Validation Nothing Nothing ( Just parsed, Dict.singleton key [ error ] )
|
||||
|
||||
|
||||
{-| -}
|
||||
fail : Validation error parsed1 field -> error -> Validation error parsed Never
|
||||
fail : FieldValidation error parsed1 field -> error -> OnlyValidation 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 : Validation error parsed1 field -> error -> Validation error parsed2 named -> Validation error parsed2 named
|
||||
withError : FieldValidation error parsed1 field -> error -> LowLevelValidation error parsed2 named constraints -> LowLevelValidation 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 -> Validation error ignored field -> error -> Validation error parsed named -> Validation error parsed named
|
||||
withErrorIf : Bool -> FieldValidation error ignored field -> error -> LowLevelValidation error parsed named constraints -> LowLevelValidation 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
|
||||
@ -97,13 +110,13 @@ withErrorIf includeError (Validation _ key _) error (Validation viewField name (
|
||||
|
||||
|
||||
{-| -}
|
||||
map : (parsed -> mapped) -> Validation error parsed named -> Validation error mapped Never
|
||||
map : (parsed -> mapped) -> LowLevelValidation error parsed named constraint -> OnlyValidation 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 Never
|
||||
fromResult : Result ( String, error ) parsed -> OnlyValidation error parsed
|
||||
fromResult result =
|
||||
case result of
|
||||
Ok parsed ->
|
||||
@ -114,13 +127,13 @@ fromResult result =
|
||||
|
||||
|
||||
{-| -}
|
||||
andMap : Validation error a named1 -> Validation error (a -> b) named2 -> Validation error b Never
|
||||
andMap : LowLevelValidation error a named1 constraints1 -> LowLevelValidation error (a -> b) named2 constraints2 -> OnlyValidation error b
|
||||
andMap =
|
||||
map2 (|>)
|
||||
|
||||
|
||||
{-| -}
|
||||
andThen : (parsed -> Validation error mapped named1) -> Validation error parsed named2 -> Validation error mapped Never
|
||||
andThen : (parsed -> LowLevelValidation error mapped named1 constraints1) -> LowLevelValidation error parsed named2 constraints2 -> OnlyValidation error mapped
|
||||
andThen andThenFn (Validation _ name ( maybeParsed, errors )) =
|
||||
case maybeParsed of
|
||||
Just parsed ->
|
||||
@ -134,7 +147,7 @@ andThen andThenFn (Validation _ name ( maybeParsed, errors )) =
|
||||
|
||||
|
||||
{-| -}
|
||||
map2 : (a -> b -> c) -> Validation error a named1 -> Validation error b named2 -> Validation error c Never
|
||||
map2 : (a -> b -> c) -> LowLevelValidation error a named1 constraints1 -> LowLevelValidation error b named2 constraints2 -> OnlyValidation error c
|
||||
map2 f (Validation _ name1 ( maybeParsedA, errorsA )) (Validation _ name2 ( maybeParsedB, errorsB )) =
|
||||
Validation Nothing
|
||||
Nothing
|
||||
@ -144,7 +157,7 @@ map2 f (Validation _ name1 ( maybeParsedA, errorsA )) (Validation _ name2 ( mayb
|
||||
|
||||
|
||||
{-| -}
|
||||
fromMaybe : Maybe parsed -> Validation error parsed Never
|
||||
fromMaybe : Maybe parsed -> OnlyValidation error parsed
|
||||
fromMaybe maybe =
|
||||
Validation Nothing Nothing ( maybe, Dict.empty )
|
||||
|
||||
|
@ -5,7 +5,7 @@ import Json.Encode as Encode
|
||||
import Pages.FormState
|
||||
|
||||
|
||||
type Validation error parsed kind
|
||||
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 (Validation)
|
||||
import Form.Validation as Validation exposing (LowLevelValidation, OnlyValidation)
|
||||
import FormData
|
||||
import Internal.Request
|
||||
import Json.Decode
|
||||
@ -887,7 +887,7 @@ formDataWithoutServerValidation :
|
||||
List
|
||||
(Form.Form
|
||||
error
|
||||
{ all | combine : Validation error combined kind }
|
||||
{ all | combine : LowLevelValidation 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 : Validation error combined kind }
|
||||
{ all | combine : LowLevelValidation 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 (Validation)
|
||||
import Form.Validation as Validation exposing (OnlyValidation)
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ all =
|
||||
checkinFormParser :
|
||||
Form
|
||||
String
|
||||
{ combine : Validation String ( Date, Date ) Never, view : a -> MyView }
|
||||
{ combine : OnlyValidation String ( Date, Date ) Never, view : a -> MyView }
|
||||
data
|
||||
checkinFormParser =
|
||||
Form.init
|
||||
@ -272,7 +272,7 @@ all =
|
||||
]
|
||||
, describe "dependent parsing" <|
|
||||
let
|
||||
linkForm : Form String { combine : Validation String PostAction Never, view : Form.Context String data -> MyView } data
|
||||
linkForm : Form String { combine : OnlyValidation String PostAction Never, 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 Never, view : Form.Context String data -> MyView } data
|
||||
postForm : Form String { combine : OnlyValidation String PostAction Never, 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 Never, view : Form.Context String data -> MyView } data
|
||||
dependentParser : Form String { combine : OnlyValidation String PostAction Never, view : Form.Context String data -> MyView } data
|
||||
dependentParser =
|
||||
Form.init
|
||||
(\kind postForm_ ->
|
||||
|
Loading…
Reference in New Issue
Block a user