Safe Haskell | Safe-Infered |
---|
This module provides a Heist frontend for the digestive-functors library.
Disclaimer: this documentation requires very basic familiarity with digestive-functors. You might want to take a quick look at this tutorial first:
https://github.com/jaspervdj/digestive-functors/blob/master/examples/tutorial.lhs
This module exports the functions digestiveSplices
and
bindDigestiveSplices
, and most users will not require anything else.
These splices are used to create HTML for different form elements. This way, the developer doesn't have to care about setting e.g. the previous values in a text field when something goes wrong.
For documentation on the different splices, see the different functions
exported by this module. All splices have the same name as given in
digestiveSplices
.
You can give arbitrary attributes to most of the elements (i.e. where it makes sense). This means you can do e.g.:
<dfInputTextArea ref="description" cols="20" rows="3" />
- digestiveSplices :: Monad m => View Text -> [(Text, Splice m)]
- bindDigestiveSplices :: Monad m => View Text -> HeistState m -> HeistState m
- dfInput :: Monad m => View v -> Splice m
- dfInputText :: Monad m => View v -> Splice m
- dfInputTextArea :: Monad m => View v -> Splice m
- dfInputPassword :: Monad m => View v -> Splice m
- dfInputHidden :: Monad m => View v -> Splice m
- dfInputSelect :: Monad m => View Text -> Splice m
- dfInputRadio :: Monad m => View Text -> Splice m
- dfInputCheckbox :: Monad m => View Text -> Splice m
- dfInputSubmit :: Monad m => View v -> Splice m
- dfLabel :: Monad m => View v -> Splice m
- dfForm :: Monad m => View v -> Splice m
- dfErrorList :: Monad m => View Text -> Splice m
- dfChildErrorList :: Monad m => View Text -> Splice m
- dfSubView :: Monad m => View Text -> Splice m
- dfIfChildErrors :: Monad m => View v -> Splice m
Core methods
bindDigestiveSplices :: Monad m => View Text -> HeistState m -> HeistState mSource
Main splices
dfInput :: Monad m => View v -> Splice mSource
Generate an input field with a supplied type. Example:
<dfInput type="date" ref="date" />
dfInputText :: Monad m => View v -> Splice mSource
Generate a text input field. Example:
<dfInputText ref="user.name" />
dfInputTextArea :: Monad m => View v -> Splice mSource
Generate a text area. Example:
<dfInputTextArea ref="user.about" />
dfInputPassword :: Monad m => View v -> Splice mSource
Generate a password field. Example:
<dfInputPassword ref="user.password" />
dfInputHidden :: Monad m => View v -> Splice mSource
Generate a hidden input field. Example:
<dfInputHidden ref="user.forgery" />
dfInputSelect :: Monad m => View Text -> Splice mSource
Generate a select button (also known as a combo box). Example:
<dfInputSelect ref="user.sex" />
dfInputRadio :: Monad m => View Text -> Splice mSource
Generate a number of radio buttons. Example:
<dfInputRadio ref="user.sex" />
dfInputCheckbox :: Monad m => View Text -> Splice mSource
Generate a checkbox. Example:
<dfInputCheckbox ref="user.married" />
dfInputSubmit :: Monad m => View v -> Splice mSource
Generate a submit button. Example:
<dfInputSubmit />
dfLabel :: Monad m => View v -> Splice mSource
Generate a label for a field. Example:
<dfLabel ref="user.married">Married: </dfLabel> <dfInputCheckbox ref="user.married" />
dfForm :: Monad m => View v -> Splice mSource
Generate a form tag with the method
attribute set to POST
and
the enctype
set to the right value (depending on the form).
Custom method
or enctype
attributes would override this
behavior. Example:
<dfForm action="/users/new"> <dfInputText ... /> ... <dfInputSubmit /> </dfForm>
dfErrorList :: Monad m => View Text -> Splice mSource
Display the list of errors for a certain field. Example:
<dfErrorList ref="user.name" /> <dfInputText ref="user.name" />
dfChildErrorList :: Monad m => View Text -> Splice mSource
Display the list of errors for a certain form and all forms below it. E.g.,
if there is a subform called "user"
:
<dfChildErrorList ref="user" />
Or display all errors for the form:
<dfChildErrorList ref="" />
Which is more conveniently written as:
<dfChildErrorList />
dfSubView :: Monad m => View Text -> Splice mSource
This splice allows reuse of templates by selecting some child of a form tree. While this may sound complicated, it's pretty straightforward and practical. Suppose we have:
<dfInputText ref="user.name" /> <dfInputText ref="user.password" /> <dfInputTextArea ref="comment.body" />
You may want to abstract the "user"
parts in some other template so you
Don't Repeat Yourself (TM). If you create a template called "user-form"
with the following contents:
<dfInputText ref="name" /> <dfInputText ref="password" />
You will be able to use:
<dfSubView ref="user"> <apply template="user-form" /> </dfSubView> <dfInputTextArea ref="comment.body" />
Utility splices
dfIfChildErrors :: Monad m => View v -> Splice mSource
Render some content only if there are any errors. This is useful for markup purposes.
<dfIfChildErrors ref="user"> Content to be rendered if there are any errors... </dfIfChildErrors>
The ref
attribute can be omitted if you want to check the entire form.