Include errors in ViewField.

This commit is contained in:
Dillon Kearns 2022-06-21 09:33:57 -07:00
parent 88d6a058f0
commit ec5bc916c1
4 changed files with 12 additions and 22 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
module Route.CreateGroup exposing (ActionData, Data, Model, Msg, route)
import DataSource exposing (DataSource)
import Dict
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import GroupName exposing (GroupName)
@ -227,7 +226,7 @@ postForm =
fieldView :
Form.Context String
-> String
-> Form.ViewField parsed Pages.FieldRenderer.Input
-> Form.ViewField String parsed Pages.FieldRenderer.Input
-> Html msg
fieldView formState label field =
Html.div []
@ -239,16 +238,10 @@ fieldView formState label field =
]
errorsForField : Form.Context String -> Form.ViewField parsed kind -> Html msg
errorsForField : Form.Context String -> Form.ViewField String parsed kind -> Html msg
errorsForField formState field =
let
errors =
formState.errors
|> Dict.get field.name
|> Maybe.withDefault []
in
(if formState.submitAttempted then
errors
field.errors
|> List.map (\error -> Html.li [] [ Html.text error ])
else

View File

@ -235,19 +235,14 @@ dependentParser =
fieldView :
Form.Context String
-> String
-> Form.ViewField parsed Pages.FieldRenderer.Input
-> Form.ViewField String parsed Pages.FieldRenderer.Input
-> Html msg
fieldView formState label field =
let
errors =
formState.errors
|> Dict.get field.name
|> Maybe.withDefault []
errorsView : Html msg
errorsView =
(if formState.submitAttempted || True then
errors
field.errors
|> List.map (\error -> Html.li [] [ Html.text error ])
else

View File

@ -219,7 +219,7 @@ andThen andThenFn ( maybe, fieldErrors ) =
field :
String
-> Field error parsed data kind constraints
-> Form error (ParsedField error parsed -> combined) data (Context error -> (ViewField parsed kind -> combinedView))
-> Form error (ParsedField error parsed -> combined) data (Context error -> (ViewField error parsed kind -> combinedView))
-> Form error combined data (Context error -> combinedView)
field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
Form
@ -250,13 +250,14 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
}
)
rawField : ViewField parsed kind
rawField : ViewField error parsed kind
rawField =
{ name = name
, value = rawFieldValue
, status = fieldStatus
, kind = ( kind, fieldParser.properties )
, parsed = maybeParsed
, errors = errors
}
myFn :
@ -264,7 +265,7 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
( Maybe (ParsedField error parsed -> combined)
, Dict String (List error)
)
, view : Context error -> ViewField parsed kind -> combinedView
, view : Context error -> ViewField error parsed kind -> combinedView
}
->
{ result : ( Maybe combined, Dict String (List error) )
@ -978,12 +979,13 @@ type alias ParsedField error parsed =
{-| -}
type alias ViewField parsed kind =
type alias ViewField error parsed kind =
{ name : String
, value : Maybe String
, status : Form.FieldStatus
, kind : ( kind, List ( String, Encode.Value ) )
, parsed : Maybe parsed
, errors : List error
}