Я успешно использовал digestive-functors с простыми формами в быстром приложении; однако я застреваю при попытке обработать список скрытых входов. Есть кое-что, что я не совсем понимаю, как использовать listOf
. Может кто-то указать мне верное направление? Благодарю.Пищеварительные -функторы и listOf
Визуализированное HTML с предыдущей страницы включает в себя следующие скрытые поля:
<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='[email protected]' />
<input type='hidden' id='messageForm.recipients.1.email' name='messageForm.recipients.1.email' value='[email protected]' />
</div>
типы данных являются:
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)
Формы:
messageForm :: (Monad m) => Form T.Text m ConfirmMessage
messageForm = 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 Recipient
recipientForm'= Recipient
<$> "email" .: text Nothing
Сообщение об ошибке Я получаю:
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:191:1)
In the expression: Recipient <$> "email" .: text Nothing
In an equation for `recipientForm'':
recipientForm' = Recipient <$> "email" .: text Nothing
Высокий, спасибо ... подход по расширению ожидаемых типов было очень полезно. – Neil