Hi Henry,

Thanks for the heads-up.  I've known for awhile that this "hole"
existed, but I never encountered it in practice, so I haven't put much
thought into it.  One of the main goals of Heist was to create a
template language where valid templates are also "valid" XML/HTML
(modulo a few obvious unavoidable points of difference).  When I
created the $() syntax for splices in attributes my choice was guided
by simplicity and ease of implementation.  I'll be happy to plug this
hole if we can come up with a reasonable solution.  Right now I'm just
not sure what that solution should look like.

I should also mention, that there's another hole in the attribute
splice syntax in that you can't pass parameters into splices like you
can with the tag syntax.  I'm not sure how to plug this hole either.
I've toyed with the idea of using "attribute-like" syntax inside the
$().

With tag syntax you'd do this:

<mySplice>
<bind tag="foo">bar</bind>
</mySplice>

With my "attribute-like" concept, the equivalent might look like this:

$(mySplice foo='bar')

Or we could go with a more lispy approach:

$(mySplice (foo bar))

I'd love to hear some ideas for how to solve the issue you mention.
The only thing I can think of right now is to define a special
attribute that somehow has the ability to expand into another
attribute(s).  Maybe something like this:

<input type="radio" hattr="mySplice"/>

To do this we'd have to hard code the behavior of "hattr" into Heist,
and we'd have to figure out some way of encoding attribute name/value
pairs.  Maybe a simple text substitution would be good enough.

Anyone else have thoughts on this issue?

On Fri, Apr 8, 2011 at 2:09 PM,  <[email protected]> wrote:
> 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
>
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to