Update examples.

This commit is contained in:
Dillon Kearns 2022-07-09 09:03:00 -07:00
parent ba1823cd82
commit 65bf2113ba
9 changed files with 49 additions and 53 deletions

View File

@ -163,7 +163,7 @@ greet =
[ Form.init
(\bar ->
Validation.succeed identity
|> Validation.withField bar
|> Validation.andMap bar
)
(\_ _ -> ())
|> Form.field "first" (Field.text |> Field.required "Required")

View File

@ -70,19 +70,18 @@ form =
Form.init
(\first last username email dob check ->
Validation.succeed User
|> Validation.withField first
|> Validation.withField last
|> Validation.withField username
|> Validation.withField email
|> Validation.withField dob
|> Validation.withField check
|> Validation.andMap first
|> Validation.andMap last
|> Validation.andMap username
|> Validation.andMap email
|> Validation.andMap dob
|> Validation.andMap check
)
(\formState firstName lastName username email dob check ->
let
errors field =
formState.errors
|> Dict.get field.name
|> Maybe.withDefault []
|> Form.errorsForField field
errorsView field =
case ( formState.submitAttempted, field |> errors ) of
@ -113,26 +112,21 @@ form =
, errorsView field
]
in
( [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column"
, Attr.style "gap" "20px"
]
, [ fieldView "Name" firstName
, fieldView "Description" lastName
, fieldView "Price" username
, fieldView "Image" email
, fieldView "Image" dob
, Html.button []
[ Html.text
(if formState.isTransitioning then
"Updating..."
[ fieldView "Name" firstName
, fieldView "Description" lastName
, fieldView "Price" username
, fieldView "Image" email
, fieldView "Image" dob
, Html.button []
[ Html.text
(if formState.isTransitioning then
"Updating..."
else
"Update"
)
]
]
)
else
"Update"
)
]
]
)
|> Form.field "first"
(Field.text
@ -262,13 +256,15 @@ view maybeUrl sharedModel static =
, Html.h1
[]
[ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ]
, Form.renderHtml
{ method = Form.Post
, submitStrategy = Form.TransitionStrategy
}
static
defaultUser
form
, form
|> Form.toDynamicTransition "user-form"
|> Form.renderHtml
[ Attr.style "display" "flex"
, Attr.style "flex-direction" "column"
, Attr.style "gap" "20px"
]
static
defaultUser
]
|> List.map Html.Styled.fromUnstyled
}

View File

@ -59,7 +59,7 @@ form =
Form.init
(\bar ->
Validation.succeed identity
|> Validation.withField bar
|> Validation.andMap bar
)
(\_ _ -> ())
|> Form.field "name" (Field.text |> Field.required "Required")

View File

@ -147,9 +147,9 @@ postForm =
Form.init
(\name description visibility ->
Validation.succeed GroupFormValidated
|> Validation.withField name
|> Validation.withField description
|> Validation.withField visibility
|> Validation.andMap name
|> Validation.andMap description
|> Validation.andMap visibility
)
(\formState name description visibility ->
( []

View File

@ -147,7 +147,7 @@ linkForm =
Form.init
(\url ->
Validation.succeed ParsedLink
|> Validation.withField url
|> Validation.andMap url
)
(\formState url ->
[ Html.h2 [] [ Html.text "Create a link" ]
@ -166,8 +166,8 @@ postForm =
Form.init
(\title body ->
Validation.succeed PostInfo
|> Validation.withField title
|> Validation.withField body
|> Validation.andMap title
|> Validation.andMap body
|> Validation.map ParsedPost
)
(\formState title body ->

View File

@ -93,7 +93,7 @@ form =
Form.init
(\username ->
Validation.succeed identity
|> Validation.withField username
|> Validation.andMap username
)
(\info username ->
( []

View File

@ -133,10 +133,10 @@ form =
Form.init
(\name description price imageUrl ->
Validation.succeed NewItem
|> Validation.withField name
|> Validation.withField description
|> Validation.withField price
|> Validation.withField imageUrl
|> Validation.andMap name
|> Validation.andMap description
|> Validation.andMap price
|> Validation.andMap imageUrl
)
(\info name description price imageUrl ->
let

View File

@ -124,8 +124,8 @@ formParser =
Form.init
(\username name ->
Validation.succeed Action
|> Validation.withField username
|> Validation.withField name
|> Validation.andMap username
|> Validation.andMap name
)
(\info username name ->
let

View File

@ -197,10 +197,10 @@ form =
Form.init
(\name description price imageUrl media ->
Validation.succeed EditInfo
|> Validation.withField name
|> Validation.withField description
|> Validation.withField price
|> Validation.withField imageUrl
|> Validation.andMap name
|> Validation.andMap description
|> Validation.andMap price
|> Validation.andMap imageUrl
|> Validation.map Edit
)
(\formState name description price imageUrl media ->