Skip to content

Conversation

@eryx67
Copy link

@eryx67 eryx67 commented Feb 26, 2015

add forms for multiple choice selection and elements for it.
Unfortunately this use case couldn't be done without extending Form.Internal.Field

@cimmanon
Copy link
Contributor

cimmanon commented Oct 14, 2016

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants