I've asked for some clarification on the relevant SO question: http://stackoverflow.com/questions/29859284/yesod-mform-and-hamlet

On Sat, Apr 25, 2015 at 6:15 AM K Sai Anirudh <kanirudh54@gmail.com> wrote:

Hi,

I am new to yesod and following the documentation to make a form. In the documentation the form template was created in .hs file itself. But I have a separate hamlet where I want to customize.

I want to access "fields" in my hamlet file. The expected type of 'generateFormPost' is (xml, Enctype) . Can anybody tell me what I should be returning from 'tableMform extra' . I think it should be in xml format. But I think I should not be using toWidget as in below example of documentation.

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")       
        |]

Please let me know if there is any misunderstanding. I have idea of how to get the form from the way done in the documentation, but I want to use a separate hamlet file, as I want to customize the look of the form.


-- 
Thanks
Sai Anirudh Kondaveeti
_______________________________________________
web-devel mailing list
web-devel@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/web-devel