mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-27 22:01:48 +03:00
Add a renderer for radio buttons.
This commit is contained in:
parent
26792db293
commit
11a3e623e7
@ -124,8 +124,7 @@ select selectAttrs enumToOption rawField =
|
||||
in
|
||||
Html.select
|
||||
(selectAttrs
|
||||
-- TODO need to handle other input types like checkbox
|
||||
++ [ Attr.value (rawField.value |> Maybe.withDefault "") -- TODO is this an okay default?
|
||||
++ [ Attr.value (rawField.value |> Maybe.withDefault "")
|
||||
, Attr.name rawField.name
|
||||
]
|
||||
)
|
||||
@ -153,6 +152,67 @@ select selectAttrs enumToOption rawField =
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
radio :
|
||||
List (Html.Attribute msg)
|
||||
->
|
||||
(parsed
|
||||
-> (List (Html.Attribute msg) -> Html msg)
|
||||
-> Html msg
|
||||
)
|
||||
->
|
||||
{ input
|
||||
| value : Maybe String
|
||||
, name : String
|
||||
, kind : ( Select parsed, List ( String, Encode.Value ) )
|
||||
}
|
||||
-> Html msg
|
||||
radio selectAttrs enumToOption rawField =
|
||||
let
|
||||
(Select parseValue possibleValues) =
|
||||
rawField.kind |> Tuple.first
|
||||
in
|
||||
Html.fieldset
|
||||
(selectAttrs
|
||||
++ [ Attr.value (rawField.value |> Maybe.withDefault "")
|
||||
, Attr.name rawField.name
|
||||
]
|
||||
)
|
||||
(possibleValues
|
||||
|> List.filterMap
|
||||
(\possibleValue ->
|
||||
let
|
||||
parsed : Maybe parsed
|
||||
parsed =
|
||||
possibleValue
|
||||
|> parseValue
|
||||
in
|
||||
case parsed of
|
||||
Just justParsed ->
|
||||
let
|
||||
renderedElement : Html msg
|
||||
renderedElement =
|
||||
enumToOption justParsed
|
||||
(\userHtmlAttrs ->
|
||||
Html.input
|
||||
([ Attr.type_ "radio"
|
||||
, Attr.value possibleValue
|
||||
, Attr.name rawField.name
|
||||
, Attr.checked (rawField.value == Just possibleValue)
|
||||
]
|
||||
++ userHtmlAttrs
|
||||
)
|
||||
[]
|
||||
)
|
||||
in
|
||||
Just renderedElement
|
||||
|
||||
Nothing ->
|
||||
Nothing
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
toHtmlProperties : List ( String, Encode.Value ) -> List (Html.Attribute msg)
|
||||
toHtmlProperties properties =
|
||||
properties
|
||||
|
Loading…
Reference in New Issue
Block a user