[Html-widget] Styling a RadioGroup in TemplateToolkit
Xavier Robin
robin0 at etu.unige.ch
Tue Nov 7 09:06:18 GMT 2006
Hello,
I'm using HTML::Widget in Catalyst, with TT2 as template to render the forms.
I defined the following radio group :
$w->element('RadioGroup', 'my_answer')->label('Answer')
->values(qw/y n/)->labels(qw/Yes No/);
and then :
$c->stash->{widget_result} = $w->process($c->req)
if ($submitted && !$error);
$c->stash->{widget_result} = $w->result else;
And in the template :
[% widget_result.elements("my_answer") %]
I get that kind of thing :
·-----------------------·
| Answer |
| Yes * |
| No * |
·-----------------------·
(Error message)
Now I would like to put "Answer" as a legend for the fieldset, in bold, the
error message inside the fieldset and some comments after or before the radio
buttons.
·--*Answer*-----------------·
| Some comment here |
| Yes * |
| No * |
| (Error message) |
| Some comment here |
·---------------------------·
I have found the following code working :
<fieldset>
<legend>
<strong class="required">
[% widget_result.elements('my_answer').label.content_list %]
</strong>
</legend>
<p>Some comment here</p>
[% FOREACH radio = widget_result.elements('my_answer').element.content_list %]
[% FOREACH radio_element = radio.content_list %]
<label for="[% radio_element.for %]" id="[% radio_element.id %]">
[% radio_element.content.1 %]
[% FOREACH input = radio_element.content.0 %]
<[% input.tag %] type="[% input.type %]"
name="[% input.name %]" id="[% input.id %]"
class="[% input.class %]" value="[% input.value %]">
[% END %]
</label>
[% END %]
[% END %]
<p>Some comment here</p>
</fieldset>
It is quite (very) tricky, but it works... as long as the form isn't
submitted. When the form gets submitted and redisplayed, with errors, the
fields are replaced by something like HTML::Element=HASH(0xb1a331c), because
of a supplementary span element that breaks all my quirk trick.
I think there is a simple way to access to :
1. The label of the radio group ("Answer")
2. Each field (label + radio button)
3. Errors (if any)
but I can't find it in the docs or in the list archives.
Could you give me a hint about that ?
Thanks
Xavier
More information about the Html-widget
mailing list