- Posts: 14
- Thank you received: 0
Limiting the length of a custom textarea
- jeff@marymoor.com
- Topic Author
- Offline
- New Member
-
Less
More
13 years 3 months ago #13462
by jeff@marymoor.com
Limiting the length of a custom textarea was created by jeff@marymoor.com
I am using Event Booking to collect biographical info on the individuals are registering. I needed a simple way to limit the length of what people type, so I updated the _renderTextarea function in helper/fields.php file as follows (see additions in red.) This uses the text input Size property to specify the total number of characters that can be typed in the textarea. It works really well! Would be a great feature to add to Event Booking.
/**
* Render textarea object
*
* @param object $row
*/
function _renderTextarea($row) {
if ($this->_loadIn == 2)
$postedValue = $row->default_values ;
else
$postedValue = JRequest::getVar($row->name, $row->default_values) ;
?>
<tr>
<td class="title_cell">
<?php
echo $row->title;
if ($row->required)
echo '<span class="required">*</span>';
?>
</td>
<td>
<textarea name="<?php echo $row->name ; ?>" rows="<?php echo $row->rows; ?>" cols="<?php echo $row->cols ; ?>" class="<?php echo $row->css_class; ?>"
onKeyDown="limitText(this.form.<?php echo $row->name ; ?>,this.form.countdown, <?php echo $row->size ; ?>);"
onKeyUp = "limitText(this.form.<?php echo $row->name ; ?>,this.form.countdown, <?php echo $row->size ; ?>);"><?php echo $postedValue; ?></textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<font size="1">
You have <input readonly type="text" name="countdown" style="width: 20px;" value="<?php echo $row->size ; ?>"</input> of <?php echo $row->size ; ?> characters left.</font>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
</td>
</tr>
/**
* Render textarea object
*
* @param object $row
*/
function _renderTextarea($row) {
if ($this->_loadIn == 2)
$postedValue = $row->default_values ;
else
$postedValue = JRequest::getVar($row->name, $row->default_values) ;
?>
<tr>
<td class="title_cell">
<?php
echo $row->title;
if ($row->required)
echo '<span class="required">*</span>';
?>
</td>
<td>
<textarea name="<?php echo $row->name ; ?>" rows="<?php echo $row->rows; ?>" cols="<?php echo $row->cols ; ?>" class="<?php echo $row->css_class; ?>"
onKeyDown="limitText(this.form.<?php echo $row->name ; ?>,this.form.countdown, <?php echo $row->size ; ?>);"
onKeyUp = "limitText(this.form.<?php echo $row->name ; ?>,this.form.countdown, <?php echo $row->size ; ?>);"><?php echo $postedValue; ?></textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<font size="1">
You have <input readonly type="text" name="countdown" style="width: 20px;" value="<?php echo $row->size ; ?>"</input> of <?php echo $row->size ; ?> characters left.</font>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
</td>
</tr>
Please Log in or Create an account to join the conversation.
Moderators: Tuan Pham Ngoc
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.