Add maxlength option to activeTextInput

Issue [#7440](https://github.com/yiisoft/yii2/issues/7440)
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
Leonardo Tietböhl
2015-02-25 09:47:35 -03:00
committed by Qiang Xue
gitea-unlock(16/)
parent f57a517f6d
commit cdfd73a9ff

12
framework/helpers/BaseHtml.php
View File

@@ -1171,6 +1171,18 @@ class BaseHtml
*/
public static function activeTextInput($model, $attribute, $options = [])
{
if (!isset($options['maxlength'])) {
return static::activeInput('text', $model, $attribute, $options);
}
$attrName = preg_replace('/[\[].*[\]]/U', '', $attribute);
foreach ($model->getActiveValidators($attrName) as $validator) {
if ($validator instanceof \yii\validators\StringValidator && $validator->max !== null) {
$options['maxlength'] = $validator->max;
break;
}
}
return static::activeInput('text', $model, $attribute, $options);
}