octicon-rss(16/)
You've already forked yii2
mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
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/)
committed by
Qiang Xue
gitea-unlock(16/)
parent
f57a517f6d
commit
cdfd73a9ff
octicon-diff(16/tw-mr-1) 1 changed files with 12 additions and 0 deletions
@@ -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