Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Provides functionality for frontend and backend integration.
This module contains functions used to glue form handling to particular server implementations and view libraries, defining the standard behaviour for handling GET and POST requests.
Field accessors can be used to write frontend libraries, mapping field values to concrete elements.
- data View v = forall a m . Monad m => View {
- viewName :: Text
- viewContext :: Path
- viewForm :: FormTree Identity v m a
- viewInput :: [(Path, FormInput)]
- viewErrors :: [(Path, v)]
- viewMethod :: Method
- getForm :: Monad m => Text -> Form v m a -> m (View v)
- postForm :: Monad m => Text -> Form v m a -> (FormEncType -> m (Env m)) -> m (View v, Maybe a)
- subView :: Text -> View v -> View v
- subViews :: View v -> [View v]
- absolutePath :: Text -> View v -> Path
- absoluteRef :: Text -> View v -> Text
- viewEncType :: View v -> FormEncType
- fieldInputText :: forall v. Text -> View v -> Text
- fieldInputChoice :: forall v. Text -> View v -> [(Text, v, Bool)]
- fieldInputChoiceGroup :: forall v. Text -> View v -> [(Text, [(Text, v, Bool)])]
- fieldInputBool :: forall v. Text -> View v -> Bool
- fieldInputFile :: forall v. Text -> View v -> Maybe FilePath
- listSubViews :: Text -> View v -> [View v]
- makeListSubView :: Text -> Int -> View v -> View v
- errors :: Text -> View v -> [v]
- childErrors :: Text -> View v -> [v]
- viewDisabled :: Text -> View v -> Bool
- debugViewPaths :: View v -> [Path]
Documentation
Finalized form - handles the form, error messages and input. Internally handles the addressing of individual fields.
Obtaining a view
getForm :: Monad m => Text -> Form v m a -> m (View v) Source
Serve up a form for a GET request - no form input
postForm :: Monad m => Text -> Form v m a -> (FormEncType -> m (Env m)) -> m (View v, Maybe a) Source
Handle a form for a POST request - evaluate with the given environment and return the result.
Operations on views
subView :: Text -> View v -> View v Source
Returns the subview of a view matching the given serialized Path
Querying a view
Low-level
absoluteRef :: Text -> View v -> Text Source
Determine an absolute path and call fromPath
on it. Useful if you're
writing a view library...
Form encoding
viewEncType :: View v -> FormEncType Source
Returns the content type of the View - depends on contained fields
Input
fieldInputText :: forall v. Text -> View v -> Text Source
Return the text data at the position referred to by the given serialized Path.
fieldInputChoice :: forall v. Text -> View v -> [(Text, v, Bool)] Source
Returns a list of (identifier, view, selected?)
fieldInputChoiceGroup :: forall v. Text -> View v -> [(Text, [(Text, v, Bool)])] Source
Returns a list of (groupName, [(identifier, view, selected?)])
fieldInputBool :: forall v. Text -> View v -> Bool Source
Returns True/False based on the field referred to by the given serialized Path.
fieldInputFile :: forall v. Text -> View v -> Maybe FilePath Source
Return the FilePath referred to by the given serialized path, if set.
List subview
listSubViews :: Text -> View v -> [View v] Source
Returns sub views referred to by dynamic list indices at the given serialized path.
Creates a sub view
Errors
errors :: Text -> View v -> [v] Source
Returns all errors related to the form corresponding to the given serialized Path
childErrors :: Text -> View v -> [v] Source
Returns all errors related to the form, and its children, pointed to by the given serialized Path.
Further metadata queries
viewDisabled :: Text -> View v -> Bool Source
Debugging
debugViewPaths :: View v -> [Path] Source
Retrieve all paths of the contained form