Duh, itβs actually easy to use monadic forms (see code below).
My main headache is additional text fields to make sure that the handler receiving the answer can also output the corresponding question. Maybe I can hide these text fields, make them uneditable, or find another way around this (but I still donβt know much about Html yet).
listEditMForm :: [(String,Int)] -> Html -> MForm App App (FormResult [(FormResult Int, FormResult Text)], Widget) listEditMForm xs extra = do ifields <- forM xs (\(s,i) -> mreq intField (String.fromString s) (Just i)) tfields <- forM xs (\(s,i) -> mreq textField (String.fromString s) (Just $ pack s)) let (iresults,iviews) = unzip ifields let (tresults,tviews) = unzip tfields let results = zip iresults tresults let views = zip iviews tviews let widget = [whamlet|
There are also some ugly things that I donβt know about, as always, always ending the result always in the external FormSuccess constructor, but I think it really depends on each use case (for example, one FormFailure or FormMissing should probably make the whole form unsuccessful / absent, but perhaps in some cases this is not necessary.)
All firmware and unpacking, perhaps, can be done more accurately, but I think that in my case I just create a combined textintField field. I think I know how to do this, but it would be neat if there was a function for combining fields.
source share