Yii2比较验证器警报不会消失

Ded*_*wan 11 passwords validation compare comparevalidator yii2

我键入一个密码,然后我在重复密码字段重复,但红色警报没有消失,当我点击提交按钮它是成功的,没有错误验证.重复密码时如何使比较警报消失?

这是模型中的规则代码

public function rules()
{
    return [
        ['username', 'filter', 'filter' => 'trim'],
        ['username', 'required'],
        ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
        ['username', 'string', 'min' => 2, 'max' => 255],

        ['email', 'filter', 'filter' => 'trim'],
        ['email', 'required'],
        ['email', 'email'],
        ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],

        ['password', 'required'],
        ['password','compare'],
        ['password', 'string', 'min' => 6],
        ['password_repeat','safe']

    ];
}
Run Code Online (Sandbox Code Playgroud)

和我的形式

<?php $form = ActiveForm::begin(); ?>

<h3>Your Account</h3>
<?= $form->field($modelUser, 'username')->textInput(['maxlength' => 45, 'class' => 'input-xlarge form-control']) ?>

<?= $form->field($modelUser, 'password')->passwordInput(['class' => 'form-control input-xlarge']) ?>

<?= $form->field($modelUser, 'password_repeat')->passwordInput(['class' => 'form-control input-xlarge']) ?>
<button class="btn btn-primary" type="submit">Continue</button>

<?php ActiveForm::end(); ?>
Run Code Online (Sandbox Code Playgroud)

这是我的截图 yii2比较验证

Vic*_*tor 16

就我而言,我刚刚更改了密码验证:

['password','compare'],
Run Code Online (Sandbox Code Playgroud)

对此:

['password_repeat', 'compare', 'compareAttribute' => 'password'],
Run Code Online (Sandbox Code Playgroud)