Accumulate button result correctly
This commit is contained in:
parent
faf5c1b2dc
commit
261f064d4e
@ -15,6 +15,8 @@ import qualified Data.Map as Map
|
|||||||
import Handler.Utils.DateTime
|
import Handler.Utils.DateTime
|
||||||
import Data.String (IsString(..))
|
import Data.String (IsString(..))
|
||||||
|
|
||||||
|
import qualified Data.Foldable as Foldable
|
||||||
|
|
||||||
-- import Yesod.Core
|
-- import Yesod.Core
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
-- import Yesod.Form.Types
|
-- import Yesod.Form.Types
|
||||||
@ -53,17 +55,19 @@ buttonForm html = do
|
|||||||
buttonIdent <- newFormIdent
|
buttonIdent <- newFormIdent
|
||||||
resultWidgetMap <- forM buttonMap $ \val -> mopt (button val) ("" { fsName = Just buttonIdent }) Nothing
|
resultWidgetMap <- forM buttonMap $ \val -> mopt (button val) ("" { fsName = Just buttonIdent }) Nothing
|
||||||
|
|
||||||
let result = asum $ nothing2miss <$> fst <$> Map.elems resultWidgetMap
|
let result = accResult $ fst <$> Map.elems resultWidgetMap
|
||||||
let viewF = (Map.!) (snd <$> resultWidgetMap)
|
let viewF = (Map.!) (snd <$> resultWidgetMap)
|
||||||
|
|
||||||
return (result, viewF)
|
return (result, viewF)
|
||||||
|
where
|
||||||
|
accResult :: Foldable f => f (FormResult (Maybe a)) -> FormResult a
|
||||||
|
accResult = Foldable.foldr accResult' FormMissing
|
||||||
|
|
||||||
nothing2miss :: FormResult (Maybe a) -> FormResult a
|
accResult' :: FormResult (Maybe a) -> FormResult a -> FormResult a
|
||||||
nothing2miss (FormSuccess Nothing) = FormMissing
|
accResult' (FormSuccess _) (FormSuccess _) = FormFailure ["Ambiguous parse"]
|
||||||
nothing2miss (FormSuccess (Just r)) = FormSuccess r
|
accResult' (FormSuccess (Just x)) _ = FormSuccess x
|
||||||
nothing2miss (FormFailure msgs) = FormFailure msgs
|
accResult' (FormFailure errs) _ = FormFailure errs
|
||||||
nothing2miss (FormMissing) = FormMissing
|
accResult' _ x = x
|
||||||
|
|
||||||
|
|
||||||
----------------------------
|
----------------------------
|
||||||
-- Buttons (old version ) --
|
-- Buttons (old version ) --
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user