diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php
index 5fa47a53fb..8434873a60 100644
--- a/framework/helpers/BaseHtml.php
+++ b/framework/helpers/BaseHtml.php
@@ -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);
}