NAME
Contentment::Form::Widget::Label - A very simple label widget
DESCRIPTION
This class adds the label()
method to Contentment::Form::Widget. This method can automatically generate a label for any widget that returns a proper value for the id()
method. It also takes the same arguments as the constructor, which can be used to set additional parameters:
[% form.widgets.username.label(
content = "Luser Name"
).render %]
You may choose to use either the render()
or begin()
/end()
methods to render the widget. However, if you use begin()
/end()
make sure to manually set content to an empty string:
[% SET label = form.widgets.username.label(content = "") %]
[% label.begin %]Luser Name[% label.end %]
This would render the same HTML as the code above, which sets the content option to "Luser Name".
The widget constructor takes the following arguments:
- for (required)
-
This should be either the ID of the widget this label belongs to or it may be the widget object itself the label should point to.
- content (optional)
-
This label class attempts to be a little smarter with creating the displayed label name. If you pick control names that follow a simple convention, this will convert the control name into a pretty capitalized name.
For example,
my $form = Contentment::Form->define( # ... widgets => { username => { name => 'username', # ID will be "username" class => 'Text', }, full_name => { name => 'full_name', # ID will be "full_name" class => 'Text', }, }, # ... ); # ...
renders:
<label for="username">Username</label> <label for="full_name">Full Name</label>
All underscores in the ID are replaced with spaces and the string is converted to title-case.
AUTHOR
Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>
LICENSE AND COPYRIGHT
Copyright 2005 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.