|Project:||Content Construction Kit (CCK)|
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):
$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.