mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-30 15:25:45 +03:00
Add checkbox and int fields.
This commit is contained in:
parent
a0f8585fd0
commit
68cfe7019f
@ -87,6 +87,66 @@ text =
|
||||
}
|
||||
|
||||
|
||||
{-| -}
|
||||
checkbox :
|
||||
Field
|
||||
error
|
||||
Bool
|
||||
{ required : ()
|
||||
}
|
||||
checkbox =
|
||||
Field
|
||||
{ type_ = "checkbox"
|
||||
, required = False
|
||||
, serverValidation = \_ -> DataSource.succeed []
|
||||
, decode =
|
||||
\rawString ->
|
||||
( (rawString == Just "on")
|
||||
|> Just
|
||||
, []
|
||||
)
|
||||
, properties = []
|
||||
}
|
||||
|
||||
|
||||
{-| -}
|
||||
int :
|
||||
{ invalid : String -> error }
|
||||
->
|
||||
Field
|
||||
error
|
||||
(Maybe Int)
|
||||
{ min : Int
|
||||
, max : Int
|
||||
, required : ()
|
||||
, wasMapped : No
|
||||
, initial : Int
|
||||
}
|
||||
int toError =
|
||||
Field
|
||||
{ type_ = "number"
|
||||
, required = False
|
||||
, serverValidation = \_ -> DataSource.succeed []
|
||||
, decode =
|
||||
\rawString ->
|
||||
case rawString of
|
||||
Nothing ->
|
||||
( Nothing, [] )
|
||||
|
||||
Just "" ->
|
||||
( Nothing, [] )
|
||||
|
||||
Just string ->
|
||||
case string |> String.toInt of
|
||||
Just parsedInt ->
|
||||
( Just (Just parsedInt), [] )
|
||||
|
||||
Nothing ->
|
||||
( Nothing, [ toError.invalid string ] )
|
||||
, properties = []
|
||||
}
|
||||
|
||||
|
||||
{-| -}
|
||||
withClientValidation : (parsed -> ( Maybe mapped, List error )) -> Field error parsed constraints -> Field error mapped { constraints | wasMapped : Yes }
|
||||
withClientValidation mapFn (Field field) =
|
||||
|
Loading…
Reference in New Issue
Block a user