Yii2: Compare validation not work

Created on 12 Jul 2018  路  3Comments  路  Source: yiisoft/yii2

On a simple ActiveForm to change user password the attributes new_password and repeat_password not are validated also if both have the same value. In the javascript validation a log on $form.data('yiiActiveForm').attributes show only 2 attribute instead 3 (email, new_password and repeat_password), the attribute lost is new_password and the validation result return always false.

Scenario configuration:

self::SCENARIO_PROFILE => ['email', 'new_password', 'repeat_password']

Validations roles:

['new_password', 'safe'],
['repeat_password', 'required', 
       'when' => function($model){
            return !empty($model->new_password);
},
       'whenClient' => "function(attribute, value){
            return $('#user-new_password').val() != '';
        }"
 ],
 ['repeat_password', 'compare', 'compareAttribute' => 'new_password', 'operator' => '=='],

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.15.1
| PHP version | 7.2.7
| Operating system | Ubuntu 18.04

JS bug

Most helpful comment

This bug fixed PR #16523. Please close this issue

All 3 comments

No more news about this bug? Still not working.
Thanks for the support!

Nope.

This bug fixed PR #16523. Please close this issue

Was this page helpful?
0 / 5 - 0 ratings