sfLimitedTextareaPlugin
0.5.1beta
for sf 1.4sf 1.3sf 1.2sf 1.1sf 1.0 MIT
Limits on the length of user input are a fact of life. But the
textarea HTML tag is notorious for its lack of support for such limits.
sfLimitedTextareaPlugin provides both a hard limit and visual feedback
as the user begins to approach the limit.
Developers
| Name |
Status |
Email |
Tom Boutell |
lead |
moc.evaknup <<ta>> mot
|
License
Copyright (c) 2008 P'unk Avenue, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfLimitedTextareaPlugin
Limits on the length of user input are a fact of life. But the
textarea HTML tag is notorious for its lack of support for such limits.
sfLimitedTextareaPlugin provides both a hard limit and visual feedback
as the user begins to approach the limit.
Requirements
Since this code does require a JavaScript framework,
it should work just fine with any version of Symfony, at least through the
1.2 series. It has been tested thoroughly with version 1.0.
Usage
<?php use_helper('LimitedTextarea') ?>
<?php echo limited_textarea_tag(
'text',
'default text',
array(
'id' => 'myid',
'max' => 1000,
'enforce' => true
)) ?>
Note that you may pass additional options if you wish. They will be
passed on to the underlying textarea_tag helper.
In this example, the length of user input is limited to 1,000 characters.
That limit is enforced: if the user types more than 1,000 characters their
additional output will be removed right away so that they know there
is a problem. If you do not want the enforcement behavior, which can
be a bit frustrating because the text insertion point tends to move,
then just don't set the enforce option.
Even if you don't set the enforce option, the user will still see
a visible indication of how many characters they have used so far
and the total number of characters allowed. That indication is
color-coded: green for the first two-thirds of the limit, yellow
for until five-sixths and, if enforcement is turned on, red for
the final sixth of the allowed number of characters. If enforcement
is turned off, then red is not used until the allowed number of
characters is exceeded, since the user would otherwise have no way
of knowing that they are past the limit.
Note that these colors actually come from CSS classes, so you can
change the behavior easily.
Of course, this is purely a convenience for end users. Your code must
still take steps to make sure the input string is not too long. Client-side
JavaScript can never be relied upon by the server and should only be used
to help honest users do something more easily.
limited_textarea_tag uses CSS class names that
begin with limited-textarea. This prevents conflicts with
other code.
Customizing the CSS
By default, the plugin will automatically output a style tag defining
the following simple styles for the "red," "green" and "yellow"
states:
.limited-textarea-red {
color: #FF0000;
}
.limited-textarea-green {
color: #00FF00;
}
.limited-textarea-yellow {
color: #FFFF00;
}
If you wish to redefine these, just set the appropriate parameter
in your app.yml file:
all:
limitedTextareaPlugin:
customcss: true
Then add your own definitions for these classes to your own CSS file.
(I could have put this in a separate stylesheet to be loaded automatically,
but loading three little CSS definitions does not justify
forcing the browser to load an additional, completely separate file.
Merge these into your own stylesheet instead.)
Changelog
0.5.1
Documentation fixes.
Credits
Tom Boutell
tom@punkave.com
Punk Avenue
Boutell.Com, Inc.