mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-06 15:28:58 +01:00
Add maxlength option to activeTextInput
Issue [#7440](https://github.com/yiisoft/yii2/issues/7440)
This commit is contained in:
committed by
Qiang Xue
parent
f57a517f6d
commit
cdfd73a9ff
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user