[Haskell-cafe] digestive-functors and listOf

Neil neilcjensen at gmail.com
Fri Jul 31 22:55:53 UTC 2015


I've been able to use digestive-functors with simple forms successfully in 
a snap application; however, I'm getting stuck when trying to handle a list 
of hidden inputs. There is something I'm not quite getting on how to use 
'listOf'. Can anyone point me in the right direction? Thanks.

The rendered html from a previous page includes the following hidden fields:

<div id='messageForm.recipients' class='inputList'>
  <input type='hidden' name='messageForm.recipients.indices' value='0' />
  <input type='hidden' id='messageForm.recipients.-1.email' name='messageForm.recipients.-1.email' value />
  <input type='hidden' id='messageForm.recipients.0.email' name='messageForm.recipients.0.email' value='emai1l at email.com' /> 
  <input type='hidden' id='messageForm.recipients.1.email' name='messageForm.recipients.1.email' value='email2 at email.com' /> </div>


The data types are:
data ConfirmMessage = ConfirmMessage {
  isoDate :: T.Text,
  subject :: T.Text,
  body    :: T.Text,
  action  :: T.Text,
  recipients :: [Recipient]} deriving (Show) 
data Recipient = Recipient {
  email :: T.Text } deriving (Show)

The forms are:
messageForm :: (Monad m) => Form T.Text m ConfirmMessagemessageForm = ConfirmMessage
  <$> "isoDate"    .: stringRead "Missing ISOdate" Nothing
  <*> "subject"    .: stringRead "Subject required" Nothing
  <*> "body"       .: stringRead "Body required" Nothing
  <*> "action"     .: stringRead "Missing action" Nothing
  <*> "recipients" .: listOf recipientForm' Nothing
recipientForm' :: (Monad m) => Formlet T.Text m RecipientrecipientForm'= Recipient
  <$> "email"      .: stringRead "Missing email" Nothing
Error message:
    Couldn't match type `Text.Digestive.Form.Internal.FormTree
                           m0 v0 m0 Recipient'
                  with `Maybe Recipient -> Form T.Text m Recipient'
    Expected type: Formlet T.Text m Recipient
      Actual type: Text.Digestive.Form.Internal.FormTree
                     m0 v0 m0 Recipient
    Relevant bindings include
      recipientForm' :: Formlet T.Text m Recipient
        (bound at src/Handler/TradeNotifyConfirm.hs:224:1)
    In the expression:
      Recipient <$> "email" .: stringRead "Missing email" Nothing
    In an equation for `recipientForm'':
        recipientForm'
          = Recipient <$> "email" .: stringRead "Missing email" Nothing

Thanks in advance,
Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150731/581d70a1/attachment.html>


More information about the Haskell-Cafe mailing list