flex-tasks-0.0.0
Safe HaskellNone
LanguageHaskell2010

FlexTask.Generic.Form

Description

Generic Yesod input form generation and related utility functions.

Synopsis

Data Types

data Alignment Source #

Inner alignment of input field elements.

Constructors

Horizontal 
Vertical 

Instances

Instances details
Show Alignment Source # 
Instance details

Defined in FlexTask.Generic.Form

Eq Alignment Source # 
Instance details

Defined in FlexTask.Generic.Form

data FieldInfo Source #

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

Instances

Instances details
Show FieldInfo Source # 
Instance details

Defined in FlexTask.Generic.Form

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

Instances details
Generic SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Associated Types

type Rep SingleChoiceSelection 
Instance details

Defined in FlexTask.Generic.Form

type Rep SingleChoiceSelection = D1 ('MetaData "SingleChoiceSelection" "FlexTask.Generic.Form" "flex-tasks-0.0.0-6jZXaKzOMKF6n8h63PhO69" 'True) (C1 ('MetaCons "SingleChoiceSelection" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAnswer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))))
Show SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Parse SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Eq SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

type Rep SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

type Rep SingleChoiceSelection = D1 ('MetaData "SingleChoiceSelection" "FlexTask.Generic.Form" "flex-tasks-0.0.0-6jZXaKzOMKF6n8h63PhO69" 'True) (C1 ('MetaCons "SingleChoiceSelection" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAnswer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))))

data MultipleChoiceSelection Source #

Same as SingleChoiceSelection, but for multiple choice input.

Instances

Instances details
Generic MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Associated Types

type Rep MultipleChoiceSelection 
Instance details

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])))
Show MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Parse MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Eq MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

type Rep MultipleChoiceSelection Source # 
Instance details

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])))

newtype Hidden a Source #

Wrapper type for generating hidden fields.

Constructors

Hidden 

Fields

Instances

Instances details
Show a => Show (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

showsPrec :: Int -> Hidden a -> ShowS #

show :: Hidden a -> String #

showList :: [Hidden a] -> ShowS #

PathPiece a => BaseForm (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler (Hidden a) Source #

PathPiece a => Formify (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Eq a => Eq (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

(==) :: Hidden a -> Hidden a -> Bool #

(/=) :: Hidden a -> Hidden a -> Bool #

PathPiece a => PathPiece (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

newtype SingleInputList a Source #

Wrapper type for lists. Use for a single field list input.

Constructors

SingleInputList 

Fields

Instances

Instances details
Show a => Show (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Show a => BaseForm (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Show a => Formify (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Parse (SingleInputList Text) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Textarea) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList String) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Integer) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Bool) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Double) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Int) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Eq a => Eq (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

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.

Methods

baseForm :: Field Handler a Source #

Instances

Instances details
BaseForm Text Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Text Source #

BaseForm Textarea Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Textarea Source #

BaseForm String Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler String Source #

BaseForm Integer Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Integer Source #

BaseForm Bool Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Bool Source #

BaseForm Double Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Double Source #

BaseForm Int Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler Int Source #

PathPiece a => BaseForm (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

baseForm :: Field Handler (Hidden a) Source #

Show a => BaseForm (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

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.

Direct use of this function is not recommended due to possible undetected invalidity of the result. It should only be used when writing manual instances of Formify. Use formify or its variants instead.

default formifyImplementation :: (Generic a, GFormify (Rep a)) => Maybe a -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

Instances

Instances details
Formify MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Text Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Textarea Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe Textarea -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

Formify String Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Integer Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Bool Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Double Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify Int Source # 
Instance details

Defined in FlexTask.Generic.Form

PathPiece a => Formify (Hidden a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Show a => Formify (SingleInputList a) Source # 
Instance details

Defined in FlexTask.Generic.Form

(BaseForm a, Formify a) => Formify (Maybe a) Source # 
Instance details

Defined in FlexTask.Generic.Form

Formify (Maybe a) => Formify [Maybe a] Source # 
Instance details

Defined in FlexTask.Generic.Form

(BaseForm a, Formify a) => Formify [a] Source # 
Instance details

Defined in FlexTask.Generic.Form

(Formify a, Formify b) => Formify (a, b) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe (a, b) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

(Formify a, Formify b, Formify c) => Formify (a, b, c) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe (a, b, c) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

(Formify a, Formify b, Formify c, Formify d) => Formify (a, b, c, d) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe (a, b, c, d) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

(Formify a, Formify b, Formify c, Formify d, Formify e) => Formify (a, b, c, d, e) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe (a, b, c, d, e) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

(Formify a, Formify b, Formify c, Formify d, Formify e, Formify f) => Formify (a, b, c, d, e, f) Source # 
Instance details

Defined in FlexTask.Generic.Form

Methods

formifyImplementation :: Maybe (a, b, c, d, e, f) -> [[FieldInfo]] -> ([[FieldInfo]], [[Rendered Widget]]) Source #

formify Source #

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.

formifyComponents :: Formify a => Maybe a -> [[FieldInfo]] -> Rendered [[Widget]] Source #

like formify, but yields the individual sub-renders instead of a combined form. Retains the layout structure given by the FieldInfo list argument. This can be used in custom forms to incorporate generated inputs.

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

buttons Source #

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.

buttonsEnum Source #

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.

dropdown Source #

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.

dropdownEnum Source #

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.

list Source #

Arguments

:: Alignment 
-> [FieldSettings FlexForm]

FieldSettings of individual fields

-> FieldInfo 

Create FieldInfo for a number of fields. Their result will be handled as a list of values.

listWithoutLabels Source #

Arguments

:: Alignment 
-> Int

Amount of fields

-> [(Text, Text)]

List of attribute and value pairs (attribute "class" for classes)

-> FieldInfo 

Same as list, but without using any field labels. Attributes and CSS classes for each field cannot be set with this function. Instead, all fields share the given list of attributes. Use list if individual configuration is required.

single :: FieldSettings FlexForm -> FieldInfo Source #

Create FieldInfo for a standalone field.

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.

Orphan instances

Show (SomeMessage FlexForm) Source # 
Instance details

Methods

showsPrec :: Int -> SomeMessage FlexForm -> ShowS #

show :: SomeMessage FlexForm -> String #

showList :: [SomeMessage FlexForm] -> ShowS #

Show (FieldSettings FlexForm) Source # 
Instance details

Methods

showsPrec :: Int -> FieldSettings FlexForm -> ShowS #

show :: FieldSettings FlexForm -> String #

showList :: [FieldSettings FlexForm] -> ShowS #