Safe Haskell | None |
---|---|
Language | Haskell2010 |
FlexTask.Generic.Form
Description
Generic Yesod
input form generation and related utility functions.
Synopsis
- data Alignment
- data FieldInfo
- data SingleChoiceSelection
- data MultipleChoiceSelection
- newtype Hidden a = Hidden {
- getHidden :: a
- newtype SingleInputList a = SingleInputList {
- getList :: [a]
- class BaseForm a where
- class Formify a where
- formify :: Formify a => Maybe a -> [[FieldInfo]] -> Rendered Widget
- formifyComponents :: Formify a => Maybe a -> [[FieldInfo]] -> Rendered [[Widget]]
- formifyComponentsFlat :: Formify a => Maybe a -> [FieldInfo] -> Rendered [Widget]
- getAnswer :: SingleChoiceSelection -> Maybe Int
- getAnswers :: MultipleChoiceSelection -> [Int]
- multipleChoiceAnswer :: [Int] -> MultipleChoiceSelection
- multipleChoiceEmpty :: MultipleChoiceSelection
- singleChoiceAnswer :: Int -> SingleChoiceSelection
- singleChoiceEmpty :: SingleChoiceSelection
- buttons :: Alignment -> FieldSettings FlexForm -> [SomeMessage FlexForm] -> FieldInfo
- buttonsEnum :: (Bounded a, Enum a) => Alignment -> FieldSettings FlexForm -> (a -> SomeMessage FlexForm) -> FieldInfo
- dropdown :: FieldSettings FlexForm -> [SomeMessage FlexForm] -> FieldInfo
- dropdownEnum :: (Bounded a, Enum a) => FieldSettings FlexForm -> (a -> SomeMessage FlexForm) -> FieldInfo
- list :: Alignment -> [FieldSettings FlexForm] -> FieldInfo
- listWithoutLabels :: Alignment -> Int -> [(Text, Text)] -> FieldInfo
- single :: FieldSettings FlexForm -> FieldInfo
- formifyInstanceBasicField :: BaseForm a => Maybe a -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]])
- formifyInstanceOptionalField :: BaseForm a => Maybe (Maybe a) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]])
- formifyInstanceSingleChoice :: (Bounded a, Enum a, Eq a) => Maybe a -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]])
- formifyInstanceMultiChoice :: (Bounded a, Enum a, Eq a) => Maybe [a] -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]])
Data Types
Inner alignment of input field elements.
Constructors
Horizontal | |
Vertical |
Data type representing a prebuilt input field.
This type is used to determine the structure of a generated form.
The form is represented by a [[FieldInfo]]
type value.
Each FieldInfo value is an individual form element.
Inner lists represent the rows of the form.
All FieldInfo values in an inner list are rendered besides each other.
The outer list represents the columns of the form.
Inner lists are rendered below each other.
Examples
Input
[[Single "field1", Single "field2"]]
Renders as:
field1 field2
Input
[[single "field1"], [single "field2"]]
Renders as:
field1 field2
Caution: Not all horizontal alignments work as one would expect.
If an element uses inner Alignment
parameters,
then the next form will only be rendered besides the last form component of the former.
Input
[[listWithoutLabels Vertical 2 []],[listWithoutLabels Vertical 2 []]]
will not result in
list11 list21 list12 list22
but instead in
list11 list12 list21 list22
data SingleChoiceSelection Source #
Generic single choice answer type. Use if you want a 'choose one of multiple' style input without caring about the underlying type.
Instances
data MultipleChoiceSelection Source #
Same as SingleChoiceSelection
, but for multiple choice input.
Instances
Generic MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.Form Associated Types
Methods from :: MultipleChoiceSelection -> Rep MultipleChoiceSelection x # to :: Rep MultipleChoiceSelection x -> MultipleChoiceSelection # | |||||
Show MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.Form Methods showsPrec :: Int -> MultipleChoiceSelection -> ShowS # show :: MultipleChoiceSelection -> String # showList :: [MultipleChoiceSelection] -> ShowS # | |||||
Formify MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.Form Methods formifyImplementation :: Maybe MultipleChoiceSelection -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source # | |||||
Parse MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.ParseInternal Methods | |||||
Eq MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.Form Methods (==) :: MultipleChoiceSelection -> MultipleChoiceSelection -> Bool # (/=) :: MultipleChoiceSelection -> MultipleChoiceSelection -> Bool # | |||||
type Rep MultipleChoiceSelection Source # | |||||
Defined in FlexTask.Generic.Form type Rep MultipleChoiceSelection = D1 ('MetaData "MultipleChoiceSelection" "FlexTask.Generic.Form" "flex-tasks-0.0.0-6jZXaKzOMKF6n8h63PhO69" 'True) (C1 ('MetaCons "MultipleChoiceSelection" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAnswers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Int]))) |
Wrapper type for generating hidden fields.
newtype SingleInputList a Source #
Wrapper type for lists. Use for a single field list input.
Constructors
SingleInputList | |
Fields
|
Instances
Show a => Show (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods showsPrec :: Int -> SingleInputList a -> ShowS # show :: SingleInputList a -> String # showList :: [SingleInputList a] -> ShowS # | |
Show a => BaseForm (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods baseForm :: Field Handler (SingleInputList a) Source # | |
Show a => Formify (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods formifyImplementation :: Maybe (SingleInputList a) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source # | |
Parse (SingleInputList Text) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Parse (SingleInputList Textarea) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods formParser :: Parser (SingleInputList Textarea) Source # | |
Parse (SingleInputList String) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Parse (SingleInputList Integer) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Parse (SingleInputList Bool) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Parse (SingleInputList Double) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Parse (SingleInputList Int) Source # | |
Defined in FlexTask.Generic.ParseInternal Methods | |
Eq a => Eq (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods (==) :: SingleInputList a -> SingleInputList a -> Bool # (/=) :: SingleInputList a -> SingleInputList a -> Bool # |
Type Classes
class BaseForm a where Source #
Members have a basic Yesod field representing Html input fields.
A BaseForm
instance of type a
is needed for generically producing forms
for [a]
and Maybe a
types.
An instance can be given manually with the Field
constructor
or using the convertField
function on an existing Field
.
Instances
BaseForm Text Source # | |
BaseForm Textarea Source # | |
Defined in FlexTask.Generic.Form | |
BaseForm String Source # | |
BaseForm Integer Source # | |
BaseForm Bool Source # | |
BaseForm Double Source # | |
BaseForm Int Source # | |
PathPiece a => BaseForm (Hidden a) Source # | |
Show a => BaseForm (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods baseForm :: Field Handler (SingleInputList a) Source # |
class Formify a where Source #
Class for generic generation of Html input forms for a given type. Bodyless instances can be declared for any type instancing Generic. Exception: Types with multiple constructors. Use utility functions for those or provide your own instance.
Minimal complete definition
Nothing
Methods
formifyImplementation Source #
Arguments
:: Maybe a | Optional default value for form. |
-> [[FieldInfo]] | Structure and type of form. |
-> ([[FieldInfo]], [[Rendered Widget]]) | remaining form structure and completed sub-renders. |
Instances
Formify MultipleChoiceSelection Source # | |
Defined in FlexTask.Generic.Form Methods formifyImplementation :: Maybe MultipleChoiceSelection -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source # | |
Formify SingleChoiceSelection Source # | |
Defined in FlexTask.Generic.Form Methods formifyImplementation :: Maybe SingleChoiceSelection -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source # | |
Formify Text Source # | |
Defined in FlexTask.Generic.Form | |
Formify Textarea Source # | |
Defined in FlexTask.Generic.Form | |
Formify String Source # | |
Defined in FlexTask.Generic.Form | |
Formify Integer Source # | |
Defined in FlexTask.Generic.Form | |
Formify Bool Source # | |
Defined in FlexTask.Generic.Form | |
Formify Double Source # | |
Defined in FlexTask.Generic.Form | |
Formify Int Source # | |
Defined in FlexTask.Generic.Form | |
PathPiece a => Formify (Hidden a) Source # | |
Defined in FlexTask.Generic.Form | |
Show a => Formify (SingleInputList a) Source # | |
Defined in FlexTask.Generic.Form Methods formifyImplementation :: Maybe (SingleInputList a) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source # | |
(BaseForm a, Formify a) => Formify (Maybe a) Source # | |
Defined in FlexTask.Generic.Form | |
Formify (Maybe a) => Formify [Maybe a] Source # | |
Defined in FlexTask.Generic.Form | |
(BaseForm a, Formify a) => Formify [a] Source # | |
Defined in FlexTask.Generic.Form | |
(Formify a, Formify b) => Formify (a, b) Source # | |
Defined in FlexTask.Generic.Form | |
(Formify a, Formify b, Formify c) => Formify (a, b, c) Source # | |
Defined in FlexTask.Generic.Form | |
(Formify a, Formify b, Formify c, Formify d) => Formify (a, b, c, d) Source # | |
Defined in FlexTask.Generic.Form | |
(Formify a, Formify b, Formify c, Formify d, Formify e) => Formify (a, b, c, d, e) Source # | |
Defined in FlexTask.Generic.Form | |
(Formify a, Formify b, Formify c, Formify d, Formify e, Formify f) => Formify (a, b, c, d, e, f) Source # | |
Defined in FlexTask.Generic.Form |
Arguments
:: Formify a | |
=> Maybe a | Optional default value for form. |
-> [[FieldInfo]] | Structure of form. |
-> Rendered Widget | Rendered form. |
This is the main way to build generic forms.
Use in conjunction with FieldInfo
builders to generate a form.
Will fail if remaining FieldInfo
structure is not empty,
indicating the form is faulty.
Examples
formify (Nothing @Int) [[single "Age"]]
Renders an input field with type=number attribute, no default value and label Age.
formify (Just ["Hallo", "Hello", "Hola", "Ciao"]) [[listWithoutLabels Vertical 4 [("class","helloInput")]]]
Renders a series of four input fields, each for the type String and organized vertically beneath each other. They are prefilled with the values given above, are assigned the Css class "helloInput" and have no labels attached to them.
formify (Nothing @SingleChoiceSelection) [[ buttons "Make your choice" [ "this one" , "or rather that one" , "I just can't decide" ] ]]
Renders a radio button field with the given title and option labels attached. No option is selected when the form is loaded.
formifyComponentsFlat :: Formify a => Maybe a -> [FieldInfo] -> Rendered [Widget] Source #
like formifyComponents
, but takes a simple list of FieldInfo
values.
The sub-renders will also be returned as a flat list without any additional structure.
Anonymous Enum Type Builders and Accessors.
getAnswer :: SingleChoiceSelection -> Maybe Int Source #
Retrieve the selected option. Nothing
if none.
getAnswers :: MultipleChoiceSelection -> [Int] Source #
Retrieve the list of selected options. []
if none.
multipleChoiceAnswer :: [Int] -> MultipleChoiceSelection Source #
Value with given list of options selected. The order of list elements is inconsequential.
multipleChoiceEmpty :: MultipleChoiceSelection Source #
Value with no options selected.
singleChoiceAnswer :: Int -> SingleChoiceSelection Source #
Value with given number option selected.
singleChoiceEmpty :: SingleChoiceSelection Source #
Value with no option selected.
Field Builders
Arguments
:: Alignment | |
-> FieldSettings FlexForm | FieldSettings for option input |
-> [SomeMessage FlexForm] | Option labels |
-> FieldInfo |
Create FieldInfo for a button field. Will turn into either radio buttons or checkboxes depending on the form type. Use with SingleChoiceSelection or MultipleChoiceSelection. Usage with a custom enum type is not recommended due to error proneness.
Arguments
:: (Bounded a, Enum a) | |
=> Alignment | |
-> FieldSettings FlexForm | FieldSettings for option input |
-> (a -> SomeMessage FlexForm) | Function from enum type values to labels. |
-> FieldInfo |
Same as buttons
, but using an explicit enum type.
Use this with custom enum types to automatically create labels
for all constructors according to the given showing scheme.
Arguments
:: FieldSettings FlexForm | FieldSettings for select input |
-> [SomeMessage FlexForm] | Option labels |
-> FieldInfo |
Create FieldInfo for a dropdown menu field. Will turn into either single or multiple selection field depending on the form type. Use with SingleChoiceSelection or MultipleChoiceSelection. Usage with a custom enum types is not recommended due to error proneness.
Arguments
:: (Bounded a, Enum a) | |
=> FieldSettings FlexForm | FieldSettings for select input |
-> (a -> SomeMessage FlexForm) | Function from enum type values to labels. |
-> FieldInfo |
Same as dropdown
, but using an explicit enum type.
Use this with custom enum types to automatically create labels
for all constructors according to the given showing scheme.
Create FieldInfo for a number of fields. Their result will be handled as a list of values.
Formify Convenience Functions
formifyInstanceBasicField :: BaseForm a => Maybe a -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #
Premade formifyImplementation
for types with BaseForm
instances.
Use within manual instances of Formify
.
formifyInstanceOptionalField :: BaseForm a => Maybe (Maybe a) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #
Same as formifyInstanceBasicField
, but for optional fields with Maybe
wrapping.
formifyInstanceSingleChoice :: (Bounded a, Enum a, Eq a) => Maybe a -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #
Premade formifyImplementation
for "single choice" forms of enum types.
Use within manual instances of Formify
.
formifyInstanceMultiChoice :: (Bounded a, Enum a, Eq a) => Maybe [a] -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #
Same as formifyInstanceSingleChoice
, but for multiple choice.