我正在关注改革库的教程。我目前有一个包含两个必填字段的表单及其设置,因此每个字段的错误消息都显示在它旁边。
postForm :: MyForm MyRequest
postForm =
MyRequest <$> name <*> msg <* inputSubmit "post it!"
where
name = labelText "name:" ++>
(inputText "" `transformEither` required "Name is required") <++ br <++ errorList
msg = labelText "message:" ++>
(inputText "" `transformEither` required "Message is required") <++ br <++ errorList
例如,如果我将此表单提交为空,则验证将失败,它将要求用户再次填写它,它将如下所示:
name: [______]
* Name is Required
message: [_____]
* Message is required
我想知道如何为表单制作一个错误列表,如下所示:
name: [______]
message: [_____]
* Name is Required
* Message is required
我试着做
postForm :: MyForm MyRequest
postForm =
(MyRequest <$> name <*> msg <* inputSubmit "post it!") <++ errorList
where
name = labelText "name:" ++>
(inputText "" `transformEither` required "Name is required") <++ br
msg = labelText "message:" ++>
(inputText "" `transformEither` required "Message is required") <++ br
但随后错误消息根本不显示!
我没有包括一个完整的可运行示例,因为为此需要一堆额外的样板,我希望我的问题只是更好地理解应用符号。以下是一些有用的函数的类型签名:
type MyForm = Form (ServerPartT IO) [Input] ReqError H.Html ()
<++ :: (Monad m, Monoid view)
=> Form m input error view proof a
-> Form m input error view () ()
-> Form m input error view proof a
errorList :: (Monad m, ToMarkup error)
=> Form m input error Html () ()
http://hackage.haskell.org/package/reform-0.2.1/docs/Text-Reform-Core.html#v:-60--43--43-