[Petal] How do I use selected/checked ?
Olaf Buwen
olaf at buwen.de
Thu Sep 1 09:48:56 BST 2005
This template:
<select>
<option
petal:repeat="entry options"
petal:attributes="value entry/lang; selected entry/selected"
petal:content="entry/title"/>
</select>
with this code:
...
print $template->process(
options => [
{lang => "foo", title => "Foobar"},
{lang => "bar", title => "Barbar", selected => 'selected'},
{lang => "baz", title => "Bazbar"},
]
);
gives this output:
<select>
<option value="foo" >Foobar</option>
<option value="bar" selected="selected">Barbar</option>
<option value="baz" >Bazbar</option>
</select>
It is not in the docs, but AFAIK it is part of the TAL spec
that an attribute is not set when the appropriate entry is missing.
I hope this helps
Olaf
More information about the Petal
mailing list