Jump to:
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-2.1 |
| Component: | text.module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi,
I am currently writing a module that enhances forms in different aspects. One of them is to add a textlimit and character-counter for textareas. Although the text-module adds #maxlength (which i need to calculate the characters left via JS) while processing a text-widget, it doesnt add it to textarea-widgets.
Of course, textareas do not take maxlength attributes in HTML, but that doesn't mean that it should be ommitted completely while processing.
So I added basically the same code from text_textfield_process to text_textarea_process, as in (line 479):
if(!empty($field['max_length']))
$element['#maxlength'] = $field['max_length'];
}Works fine. But how is it used you may ask. Well currently I am hooking into theme_text_textarea to look for a #maxlength attribute in the element. If found, this gets added to a static array where all textareas (their id's) get stored with the corresponding maxlength. Additionally I hook into preprocess page where I add all the recorded textareas to the drupal JS settings. Last but not least, I have a small jquery-plugin that parses all elements in the setting and adds a textlimit (plus char-count-display) to these textareas when the document is ready.
Comments
#1
hum sorry, this was meant to be:
if(!empty($field['max_length']))$element[$field_key]['#maxlength'] = $field['max_length'];
#2
Can I use this to give a textarea in a profile a maximum length? I'm slightly unclear as to where this code goes and what I'd need to do to use it within the context of the profile module.