Skip to content

Add maxlength attribute to CHtml::activeTextArea #246

Closed
qiangxue opened this Issue Feb 15, 2012 · 3 comments

4 participants

@qiangxue
Yii Software LLC member

This is a feature request, not a bug.

It would be nice if CHtml:activeTextArea would render the maxlength attribute for textareas. This attribute is supported in HTML5 and already works in most current browsers.

The idea came from reading the code for CHtml::activeInputField that already does this with the max length from the model for inputs of type text and password.

Migrated from http://code.google.com/p/yii/issues/detail?id=2891


earlier comments

ejtb87 said, at 2011-10-22T20:18:14.000Z:

I tried copying the code from activeInputField into activeTextArea and it works as expected. This is how it would look like in the end: public static function activeTextArea($model,$attribute,$htmlOptions=array()) { self::resolveNameID($model,$attribute,$htmlOptions); self::clientChange('change',$htmlOptions); if(!isset($htmlOptions['maxlength'])) { foreach($model->getValidators($attribute) as $validator) { if($validator instanceof CStringValidator && $validator->max!==null) { $htmlOptions['maxlength']=$validator->max; break; } } } else if($htmlOptions['maxlength']===false) unset($htmlOptions['maxlength']); if($model->hasErrors($attribute)) self::addErrorCss($htmlOptions); $text=self::resolveValue($model,$attribute); return self::tag('textarea',$htmlOptions,isset($htmlOptions['encode']) && !$htmlOptions['encode'] ? $text : self::encode($text)); }

qiang.xue said, at 2012-01-01T03:37:10.000Z:

set for 1.1.10 milestone

qiang.xue said, at 2012-01-01T03:37:36.000Z:

set for 1.1.10 milestone

@yjeroen
yjeroen commented Mar 1, 2012

If you want this to work with backwards compatiblity, you'd need javascript.

Something like this: http://psacake.com/web/js.asp

@resurtm
resurtm commented May 19, 2012

@yjeroen better jQuery way of imposing textarea's maxlength: http://stackoverflow.com/a/5936578/571465

PS: Subscribe.

@cebe
Yii Software LLC member
cebe commented Nov 28, 2012

Closed for reasons discussed in #729

@cebe cebe closed this Nov 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.