Skip to content

Commit

Permalink
Simplify and adapt radio field
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Sep 16, 2023
1 parent 9e8f14b commit 701fa22
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions IHP/View/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -816,41 +816,23 @@ selectField field items = FormField
-- > render NewView { .. }
radioField :: forall fieldName model item.
( ?formContext :: FormContext model
, ?context::ControllerContext
, HasField fieldName model (SelectValue item)
, HasField "meta" model MetaBag
, KnownSymbol fieldName
, KnownSymbol (GetModelName model)
, CanSelect item
, InputValue (SelectValue item)
) => Proxy fieldName -> [item] -> FormField
radioField field items = FormField
radioField field items = (selectField field items)
{ fieldType =
let
itemToTuple :: item -> (Text, Text)
itemToTuple item = (selectLabel item, inputValue (selectValue item))
in
RadioInput (map itemToTuple items)
, fieldName = cs fieldName
, fieldLabel = removeIdSuffix $ fieldNameToFieldLabel (cs fieldName)
, fieldValue = inputValue ((getField @fieldName model :: SelectValue item))
, fieldInputId = cs (lcfirst (getModelName @model) <> "_" <> cs fieldName)
, validatorResult = getValidationViolation field model
, fieldClass = ""
, labelClass = ""
, disabled = False
, disableLabel = False
, disableGroup = False
, disableValidationResult = False
, additionalAttributes = []
, cssFramework = ?formContext.cssFramework
, helpText = ""
, placeholder = ""
, required = False
, autofocus = False
}
where
fieldName = symbolVal field
FormContext { model } = ?formContext
{-# INLINE radioField #-}

class CanSelect model where
Expand Down

0 comments on commit 701fa22

Please sign in to comment.