嗨,我是 yesod 的新手,并按照文档制作表格。在文档中,表单模板是在 .hs 文件本身中创建的。但我有一个单独的小村庄我想定制。
我想访问我的 hamlet 文件中的“字段”。'generateFormPost' 的预期类型是 (xml, Enctype) 。谁能告诉我应该从 'tableMform extra' 返回什么。我认为它应该是xml格式。但我认为我不应该像下面的文档示例那样使用 toWidget。
tableMform extra = do
fields <- forM lis (\(w,h) -> mopt intField "this is not used" (Just h) )
return (fields) ---I know this line has the type error. Can anybody suggest how to deal with it
{-
--I am referring this code from yesod website to make my form. In this it was using runFormGet, but I want use generateFormPost and moreover it was creating a widget which is used in displaying the website. I don't want to create the widget here but in my hamlet file where the 'fields' is accessed via interpolation.
personForm :: Html -> MForm Handler (FormResult Person, Widget)
personForm extra = do
(nameRes, nameView) <- mreq textField "this is not used" Nothing
(ageRes, ageView) <- mreq intField "neither is this" Nothing
let personRes = Person <$> nameRes <*> ageRes
let widget = do
toWidget
[lucius|
##{fvId ageView} {
width: 3em;
}
|]
[whamlet|
#{extra}
<p>
Hello, my name is #
^{fvInput nameView}
\ and I am #
^{fvInput ageView}
\ years old. #
<input type=submit value="Introduce myself">
|]
return (personRes, widget)
-}
getHomeR :: Handler Html
getHomeR = defaultLayout $ do
-- Generate the form to be displayed
(fields, enctype) <- generateFormPost tableMform
let (fires,fiview) = unzip fields
$(widgetFile "layout")
|]
如果有任何误解,请告诉我。我知道如何通过文档中的方式获取表单,但我想使用单独的 hamlet 文件,因为我想自定义表单的外观。
谢谢赛
编辑:对不起,我不清楚。我试图制作一个 Mform,而不是在“.hs”文件中创建表单的布局,我想在 hamlet 文件中给出布局。我已经通过http://pastebin.com/fwpZsKXy完成了。但是在这样做之后,我可以根据需要将它分成两个文件。我已经解决了这些错误。不管怎么说,多谢拉