Add Field.map helper.

This commit is contained in:
Dillon Kearns 2022-07-05 09:56:49 -07:00
parent 0275c296d3
commit cdf58c62e0

View File

@ -3,7 +3,7 @@ module Pages.Field exposing
, select, range, OutsideRange(..)
, date, time, TimeOfDay
, Field(..), FieldInfo, exactValue
, required, withClientValidation, withInitialValue
, required, withClientValidation, withInitialValue, map
, email, password, search, telephone, url, textarea
, withMax, withMin, withStep, withMinLength, withMaxLength
, withServerValidation
@ -35,7 +35,7 @@ module Pages.Field exposing
## Field Configuration
@docs required, withClientValidation, withInitialValue
@docs required, withClientValidation, withInitialValue, map
## Text Field Display Options
@ -580,6 +580,14 @@ range info field =
|> (\(Field innerField _) -> Field { innerField | initialValue = Just (info.initial >> Form.Value.toString) } (FieldRenderer.Input FieldRenderer.Range))
{-| -}
map : (parsed -> mapped) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
map mapFn field_ =
withClientValidation
(\value -> ( Just (mapFn value), [] ))
field_
{-| -}
withClientValidation : (parsed -> ( Maybe mapped, List error )) -> Field error parsed data kind constraints -> Field error mapped data kind { constraints | wasMapped : Yes }
withClientValidation mapFn (Field field kind) =