| Alexey Borzov 2007-09-15, 8:01 am |
| Hi,
Christoph Boget wrote:
> I'm not sure I understand why you would pass a renderer to an element. Is
> it just to define a renderer (and possibly a template) for that individual
> element? Would /should the template be defined as part of the attributes
> that get passed to the contructor? And both the renderer and template
> would/should be used in the toHTML() method?
You don't usually pass the renderer to the element yourself, you set it up (by
e.g. providing necessary templates) then pass to HTML_QuickForm's accept()
method. The method takes care of passing the renderer to each element and the
renderer takes care of aggregating the elements' HTML and adding that to the
templates.
toHtml() methods are there just to output the element itself, not "element as a
part of the form". There are some elements that do use the Default renderer in
their toHtml() method, but that's basically done to prevent repeating the code
already present in their or their parent's accept() method (e.g. group).
So yes, you can use a renderer in toHtml() method and you can set the template
for your element if it is complex enough to need a template. But bear in mind
that toHtml() needs to just output the element itself or there will be trouble
with integrating your element into the form's template.
|