[Haskell-cafe] How to deal with HTML input select option on a form using in a scotty and Text.Blaze.Html5

Tebogo Sikwane tebogos at gmail.com
Thu Feb 27 03:57:00 UTC 2020

I am using scotty
and Text.Blaze.Html5 Text.Digestive Text.Digestive.Blaze.Html5
 What I want to achieve is a list of options as shown below.

I have a Option sum type and will like to restrict the user to those

data Options = Option1 | Option2 | Option3 | Option4 deriving Show

Below is the Register record typeY

data Register = Register

{ regName::Text

, regOption::Options

} deriving (Show,Eq)

My problem is with Text.Digestive.choice.
I don't know how to use it with Text.Digestive.Blaze.Html5 and will
appreciate your help on the correct way to achieve this.
I have tried to use the code below but battle to get it right.

registerForm :: Monad m => Form Text m Register
registerForm = Register
   <$> "name"     .: text Nothing
   <*> "options" .: choice options Nothing
     options= [(Option1,"Option1"),(Option2,"Option2"),  (Option3,
registerView:: View H.Html -> H.Html
registerView view = do
    label     "name" view "Name: "
    inputText "name" view
    label       "options" view "Options: "
    inputSelect "options" view

I get the following error when I compile my code:

/root/work/src/Adapter/HTTP/Web/Auth.hs:107:29: error:
    • Couldn't match type ‘Text’ with ‘Char’
        arising from the literal ‘"Option1"’
    • In the first argument of ‘pack’, namely ‘"Option1"’
      In the expression: pack "Option1"
      In the expression: (Option1, pack "Option1")
107 |     options=  [(Option1,pack "Option1"),(Option2,pack
"Option2"),(Option3,pack "Option3"),(Option4,pack "Option4")]

Your help will be highly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200227/f71b5204/attachment.html>

More information about the Haskell-Cafe mailing list