[Html-widget] Styling a RadioGroup in TemplateToolkit

Carl Franks fireartist at gmail.com
Wed Nov 8 10:46:24 GMT 2006


On 07/11/06, Xavier Robin <robin0 at etu.unige.ch> wrote:
> $w->element('RadioGroup', 'my_answer')->label('Answer')
>     ->values(qw/y n/)->labels(qw/Yes No/);

> 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        |
> ·---------------------------·

If you use legend( 'Answer' ) instead of label( 'Answer' ) - that'll
do what you want.

I'm considering the possibility of making RadioGroup a subclass of
Block, so that it inherits it's _pre_content_elements() and
_post_content_elements() methods.
That would allow either new methods on RadioGroup, or you to more
easily subclass RadioGroup to acheive this.

Getting the error message in that position is still harder, as that's
done later, by the Container class, after the RadioGroup has already
been built.

> 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.

Sorry, when I wrote my first reply, I didn't notice your comment about errors.
I can't see any way round that at the moment without creating your own
Element and Container class.

> 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.

No, there's not really any simple was to access these things.
One thing I'm currently working on is changing $result->elements() so
that it can return more generic objects instead of HTML::Element
objects. This would allow you to access element properties more
easily.
Sorry I can't be more helpful than that at the moment!

Carl



More information about the Html-widget mailing list