![]() |
|
sfLimitedTextareaPlugin - 0.5.1textarea_tag alternative that supports limits on total characters entered |
|
![]() |
1
user
Sign-in
to change your status |
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. |
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.
| Name | Status | |
|---|---|---|
|
|
lead | moc.evaknup <<ta>> mot |
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.
| Version | License | API | Released |
|---|---|---|---|
| 0.5.1beta | MIT license | 0.5.0beta | 30/12/2008 |
| 0.5.0beta | MIT license | 0.5.0beta | 30/12/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 0.5.1beta | MIT license | 0.5.0beta | 30/12/2008 |
| 0.5.0beta | MIT license | 0.5.0beta | 30/12/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 0.5.1beta | MIT license | 0.5.0beta | 30/12/2008 |
| 0.5.0beta | MIT license | 0.5.0beta | 30/12/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 0.5.1beta | MIT license | 0.5.0beta | 30/12/2008 |
| 0.5.0beta | MIT license | 0.5.0beta | 30/12/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 0.5.1beta | MIT license | 0.5.0beta | 30/12/2008 |
| 0.5.0beta | MIT license | 0.5.0beta | 30/12/2008 |
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.
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.
<?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.
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.)
Documentation fixes.
Tom Boutell
