digestive-functors
digestive-functors copied to clipboard
add fieldInputChoices for multiple choices selection
add forms for multiple choice selection and elements for it. Unfortunately this use case couldn't be done without extending Form.Internal.Field
I've been testing this, but it seems like it doesn't properly set the values as selected when looking at the view prior to posting the form? I've tried poking at it myself and can't quite figure out how to debug where the problem is.
module Test () where
import Data.Text (Text)
import Control.Monad ((=<<))
import Text.Digestive
x :: [Text]
x = ["a", "b", "c"]
choiceTest :: Monad m => Formlet Text m [Text]
choiceTest = choices (zip x x)
--test :: [(Text, Text, Bool)]
test = fieldInputChoices "" =<< (getForm "x" $ choiceTest Nothing)
--test2 :: [(Text, Text, Bool)]
test2 = fieldInputChoices "" =<< (getForm "x" $ choiceTest (Just ["a", "b"]))
Output:
*Test> test
[("0","a",False),("1","b",False),("2","c",False)]
*Test> test2
[("0","a",False),("1","b",False),("2","c",False)]
Personally, I think it might be better if Choice
was modified to have a type signature of [(Text, [(Text, (a, v))])] -> [Int] -> Field v [(a, Int)]
, rather than adding a Choices
type. The choice
collection of functions could easily be converted to working with lists while still returning a Maybe
to keep them backwards compatible (see the file
and fileMultiple
functions).