yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

ActiveForm not use redefine id from options in js #18037

Open bscheshirwork opened 4 years ago

bscheshirwork commented 4 years ago

What steps will reproduce the problem?

        <?= $form->field($model, $attribute = 'is_matching_registration')->checkbox([
            'id' => $idPrefix . '-' . $attribute,
        ]); ?>

What is the expected result?

errors fill to checkbox

What do you get instead?

id for js is not redefine id: "relativeaddressofregistration-settlement" input: "#relative-0-addressofregistration-settlement" error not fill to field

Additional info

Q A
Yii version 2.0.?
PHP version 7.3
Operating system
yii-bot commented 4 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

bscheshirwork commented 4 years ago

1.add field to activeForm 2.redefine id in options

        <?= $form->field($model, $attribute = 'is_matching_registration')->checkbox([
            'id' => $idPrefix . '-' . $attribute,
        ]); ?>

3 fill errors with new id from js

                form.yiiActiveForm('updateMessages', data.error.messages, true);

note: in https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.activeForm.js

                data = $form.data('yiiActiveForm'),

representation of field have original ID, not id from options

samdark commented 4 years ago

Isn't data = $form.data('yiiActiveForm'), supposed to use names, not IDs?

bscheshirwork commented 4 years ago

https://github.com/yiisoft/yii2/blob/eb7b23d117664ee61ab08c15072ee1a3fa01ef66/framework/assets/yii.activeForm.js#L278-L288

attributes use id for any case I think https://github.com/yiisoft/yii2/blob/eb7b23d117664ee61ab08c15072ee1a3fa01ef66/framework/assets/yii.activeForm.js#L478-L487

https://github.com/yiisoft/yii2/blob/eb7b23d117664ee61ab08c15072ee1a3fa01ef66/framework/assets/yii.activeForm.js#L793-L795