durusmail: quixote-users: How to add label to Form ?
How to add label to Form ?
2005-05-22
2005-05-23
How to add label to Form ?
mso@oz.net
2005-05-23
Vincent Delft wrote:
> I like the Quixote form capabilities, but I'm facing a
> problem: How to display simple static htmltext between
> labels ?
>
> I've looked into the form.py and widget.py how I can
> do this, but I've not found any solutions.

I did this in a Form subclass but I later took it out so I don't have the
code.  Attach the HTML to a widget attribute or method (I used .before,
meaning before the widget.)  Override Form._render_widgets something like
this:

    def _render_widgets(self):
        r = TemplateIO(html=True)
        for widget in self.widgets:
            try:                       # Stanza added.
                r += widget.before
            except AttributeError:
                pass
            r += widget.render()
        return r.getvalue()

Because each widget puts a 
around itself, your addition will show up on a separate line. This code works only for regular widgets, not child (composite) widgets or submit widgets. Likewise, you can override Form._render_body to add some extra HTML at the top or bottom of the form. I use this to add a "* means required" message. REQUIRED_MESSAGE = htmltext( '
* indicates required field.') class Form: def _render_body(self): """Add required notice.""" r = TemplateIO(html=True) if self.has_errors(): r += self._render_error_notice() r += self._render_required_notice() # Line added. if self.caption: r += self.caption r += '\n' r += self._render_widgets() r += self._render_submit_widgets() return r.getvalue() def _render_required_notice(self): for widget in self.widgets: if widget.is_required(): break else: return '' # No required widgets. return REQUIRED_MESSAGE
reply