{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9811","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9811/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9811/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9811/events","html_url":"https://github.com/yiisoft/yii2/issues/9811","id":109323802,"number":9811,"title":"CompareValidator client validation does not work with prefixed attributes","user":{"login":"SilverFire","id":4499203,"avatar_url":"https://avatars.githubusercontent.com/u/4499203?v=3","gravatar_id":"","url":"https://api.github.com/users/SilverFire","html_url":"https://github.com/SilverFire","followers_url":"https://api.github.com/users/SilverFire/followers","following_url":"https://api.github.com/users/SilverFire/following{/other_user}","gists_url":"https://api.github.com/users/SilverFire/gists{/gist_id}","starred_url":"https://api.github.com/users/SilverFire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SilverFire/subscriptions","organizations_url":"https://api.github.com/users/SilverFire/orgs","repos_url":"https://api.github.com/users/SilverFire/repos","events_url":"https://api.github.com/users/SilverFire/events{/privacy}","received_events_url":"https://api.github.com/users/SilverFire/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-01T15:26:39Z","updated_at":"2015-10-01T18:28:56Z","closed_at":null,"body":"In case of using form fields with prefixed attributes, the ID of input will be `model-prefix-attribute` (for example bellow `user-0-password`). During the generation of client validation JS in `CompareValidator`, the `compareAttribute` (which have to contain ID of target input) will be set to `model-password` instead of `model-0-password` (see `CompareValidator.php:219`), so the JS will generate false errors during the validation.\r\n\r\nview.php:\r\n```php\r\nuse yii\\widgets\\ActiveForm;\r\n\r\n$form = ActiveForm::begin();\r\nforeach ($models as $i => $model) {\r\n    print $form->field($model, \"[$i]password\");\r\n    print $form->field($model, \"[$i]confirm_password\");\r\n}\r\n$form->end();\r\n```\r\n\r\nmodel.php:\r\n```php\r\nclass User extents Model {\r\n...\r\n    function rules() {\r\n        return [\r\n            [\r\n                    ['password'],\r\n                    'compare',\r\n                    'compareAttribute' => 'confirm_password',\r\n                    'on' => ['create'],\r\n                ],\r\n        ];\r\n    }\r\n...\r\n}\r\n```\r\n\r\nWorkaround: set `enableClientValidation` to `false` in model and use ajax validation with `ActiveForm::validateMultiple`\r\n\r\nAnd I don't know, how to pass full attribute with prefix form `ActiveForm` to `CompareValidator`"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/144809735","html_url":"https://github.com/yiisoft/yii2/issues/9811#issuecomment-144809735","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9811","id":144809735,"user":{"login":"bladeroot","id":10207103,"avatar_url":"https://avatars.githubusercontent.com/u/10207103?v=3","gravatar_id":"","url":"https://api.github.com/users/bladeroot","html_url":"https://github.com/bladeroot","followers_url":"https://api.github.com/users/bladeroot/followers","following_url":"https://api.github.com/users/bladeroot/following{/other_user}","gists_url":"https://api.github.com/users/bladeroot/gists{/gist_id}","starred_url":"https://api.github.com/users/bladeroot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bladeroot/subscriptions","organizations_url":"https://api.github.com/users/bladeroot/orgs","repos_url":"https://api.github.com/users/bladeroot/repos","events_url":"https://api.github.com/users/bladeroot/events{/privacy}","received_events_url":"https://api.github.com/users/bladeroot/received_events","type":"User","site_admin":false},"created_at":"2015-10-01T18:28:56Z","updated_at":"2015-10-01T18:28:56Z","body":":+1:"}}