{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9300","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9300/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9300/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9300/events","html_url":"https://github.com/yiisoft/yii2/issues/9300","id":98849777,"number":9300,"title":"Dynamic Form validation - case of radio/checkbox lists","user":{"login":"fabioaccetta","id":2943981,"avatar_url":"https://avatars.githubusercontent.com/u/2943981?v=3","gravatar_id":"","url":"https://api.github.com/users/fabioaccetta","html_url":"https://github.com/fabioaccetta","followers_url":"https://api.github.com/users/fabioaccetta/followers","following_url":"https://api.github.com/users/fabioaccetta/following{/other_user}","gists_url":"https://api.github.com/users/fabioaccetta/gists{/gist_id}","starred_url":"https://api.github.com/users/fabioaccetta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabioaccetta/subscriptions","organizations_url":"https://api.github.com/users/fabioaccetta/orgs","repos_url":"https://api.github.com/users/fabioaccetta/repos","events_url":"https://api.github.com/users/fabioaccetta/events{/privacy}","received_events_url":"https://api.github.com/users/fabioaccetta/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-03T22:26:29Z","updated_at":"2016-06-07T15:21:44Z","closed_at":null,"body":"I hope I have done the right choice opening a new issue instead of commenting [this one](https://github.com/yiisoft/yii2/issues/1422).\r\n\r\nI have a relation between `$product` model with many `$color` ones; the color form (the row to be inserted inside the product form) is like this:\r\n```php\r\n[...]\r\n$colors = [\r\n   'red' => 'Red',\r\n   'green' => 'Green',\r\n   'blue' => 'Blue',\r\n];\r\n// $i represents an incremental variable,\r\n// valued with the next available index of the colors array (already created)\r\necho $form->field($color, \"[{$i}]name\")\r\n\t->inline(true)\r\n\t->radioList($colors)\r\n;\r\n// inside the view, we will suppose that $product has already 1 $color for semplicity,\r\n// so $i will be 1\r\n[...]\r\n```\r\nThe corresponding html is:\r\n```html\r\n[...]\r\n<div class=\"form-group field-color-1-name required\">\r\n   <label for=\"color-1-name\" class=\"control-label\">Name</label>\r\n   <div>\r\n      <input type=\"hidden\" value=\"\" name=\"Color[1][name]\">\r\n      <div id=\"color-1-name\">\r\n         <label class=\"radio-inline\">\r\n            <input type=\"radio\" value=\"red\" name=\"Color[1][name]\"> Red\r\n         </label>\r\n         <label class=\"radio-inline\">\r\n            <input type=\"radio\" value=\"green\" name=\"Color[1][name]\"> Green\r\n         </label>\r\n         <label class=\"radio-inline\">\r\n            <input type=\"radio\" value=\"blue\" name=\"Color[1][name]\"> Blue\r\n         </label>\r\n      </div>\r\n      <p class=\"help-block help-block-error\"></p>\r\n   </div>\r\n</div>\r\n[...]\r\n```\r\nAccording to the [yii2-cookbook](https://github.com/samdark/yii2-cookbook/blob/master/book/forms-activeform-js.md#adding-and-removing-fields-dynamically), I need to execute this after the ajax call:\r\n```javascript\r\nvar attribute = {\r\n    'id': 'color-1-name',\r\n    'name': '[1]name',\r\n    'container': '.field-color-1-name',\r\n    'input': '#color-1-name',\r\n    'error': '.field-color-1-name .help-block'\r\n};\r\n$('#product-form').yiiActiveForm('add', attribute);\r\n```\r\nOn validation (on submit for example), my required radio buttons are empty and considered valid (green), while other required fields are considered invalid with error message (red). What I miss?"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/224315269","html_url":"https://github.com/yiisoft/yii2/issues/9300#issuecomment-224315269","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9300","id":224315269,"user":{"login":"IgorCode","id":5962736,"avatar_url":"https://avatars.githubusercontent.com/u/5962736?v=3","gravatar_id":"","url":"https://api.github.com/users/IgorCode","html_url":"https://github.com/IgorCode","followers_url":"https://api.github.com/users/IgorCode/followers","following_url":"https://api.github.com/users/IgorCode/following{/other_user}","gists_url":"https://api.github.com/users/IgorCode/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorCode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorCode/subscriptions","organizations_url":"https://api.github.com/users/IgorCode/orgs","repos_url":"https://api.github.com/users/IgorCode/repos","events_url":"https://api.github.com/users/IgorCode/events{/privacy}","received_events_url":"https://api.github.com/users/IgorCode/received_events","type":"User","site_admin":false},"created_at":"2016-06-07T15:21:44Z","updated_at":"2016-06-07T15:21:44Z","body":"I'm facing the same issue, radioList control is validated for initial control but not for added/cloned ones. Inspecting `$(\"#form\").data('yiiActiveForm').attributes` reveals that new radio list controls are not added for validation."}}
{"actor":{"display_login":"IgorCode"}}