The purpose of this message is a "heads up."  Here is what I wanted to
do with with heist:  I wanted to create a form that contains a set of radio
buttons.  Additionally, I wanted to have one of the radio buttons
checked by default.  This desire led to a world of hurt.

First attempt:

<input type="radio" name="currency" value="Pesos" checked="$(pesos)"/> Pesos
<input type="radio" name="currency" value="USDollars" checked="$(dollars)"/> US 
Dollars


where in my haskell code, I had a bind like the following:

[ ("pesos","Checked"),
  ("dollars", "") ]

The problem with this was that the browsers (Firefox & Chrome) don't
look at the value of the checked attribute.  They just check the last
radio button that HAS A CHECKED ATTRIBUTE, ignoring the value.  Thus in
the above example, the USDollars checkbox was checked, even though I
wanted the Pesos value checked by default.

Next I tried:

<input type="radio" name="currency" value="Pesos" $(pesos)/> Pesos
<input type="radio" name="currency" value="USDollars" $(dollars)/> US Dollars

where in my haskell code, I had a bind like the following:

[ ("pesos","Checked=\"Checked\""),
  ("dollars", "") ]

but Heist complained that my XML was invalid, which it was, sadly.

That meant I had to create my own custom Splice with heist, which I
did as follows:

getCurrency :: LoanM Currency  -- (LoanM is my Monad) 
getCurrency = do
 loan <- get >>= return . internalData_loan . saved_internalData
 return $ loan_usualCurrency loan
 
radio :: Show a => Text -> a -> Bool -> [X.Node]
radio name value checked =  [X.Element "input" attributes []]
  where attributes = [("type","radio"),
                      ("name",name),
                      ("value",T.pack . show $ value)] ++
          if checked then [("checked","checked")] else []

radioButton currency = do
  c <- lift getCurrency
  return $ radio "currency" currency (currency == c)
radioPesos   :: Splice LoanM
radioPesos = radioButton Pesos
radioDollars :: Splice LoanM
radioDollars = radioButton USDollars


This works, but is pretty painful.  I don't know if as designers of
Heist you want to address this issue, but as far as I can tell, if you
have an input form with checkboxes or radiobuttons, you will have to
resort to something like the above in order to set default values for
input forms.

Best wishes, 
Henry Laxen

-- 
Nadine & Henry Laxen    Belle, Venus, Aphrodite
10580 N. McCarran Blvd. Adonis, Miss Parker & Jarod
Suite 115-396           Via Alta # 6
Reno, Nevada            Chapala, Jalisco, Mexico 
89503-1896              CP 45900
         The rest is silence.  (Hamlet)

_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to