{"action":"created","issue":{"url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/126","repository_url":"https://api.github.com/repos/wbraganca/yii2-dynamicform","labels_url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/126/comments","events_url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/126/events","html_url":"https://github.com/wbraganca/yii2-dynamicform/issues/126","id":133033088,"number":126,"title":"select2 gets duplicated model value when on insertion of new item","user":{"login":"kankerlijer","id":10619287,"avatar_url":"https://avatars.githubusercontent.com/u/10619287?v=3","gravatar_id":"","url":"https://api.github.com/users/kankerlijer","html_url":"https://github.com/kankerlijer","followers_url":"https://api.github.com/users/kankerlijer/followers","following_url":"https://api.github.com/users/kankerlijer/following{/other_user}","gists_url":"https://api.github.com/users/kankerlijer/gists{/gist_id}","starred_url":"https://api.github.com/users/kankerlijer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kankerlijer/subscriptions","organizations_url":"https://api.github.com/users/kankerlijer/orgs","repos_url":"https://api.github.com/users/kankerlijer/repos","events_url":"https://api.github.com/users/kankerlijer/events{/privacy}","received_events_url":"https://api.github.com/users/kankerlijer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-11T17:16:49Z","updated_at":"2016-02-11T17:28:24Z","closed_at":null,"body":"![image](https://cloud.githubusercontent.com/assets/10619287/12983550/05fbe51c-d0ea-11e5-9536-29540b6017d6.png)\r\n\r\n```\r\n`<?php\r\n        DynamicFormWidget::begin([\r\n                'widgetContainer' => 'dynamicform_wrapper_tochtprodukt_'.$type->produkttype_id, // required: only alphanumeric characters plus \"_\" [A-Za-z0-9_]\r\n                'widgetBody' => '.containerTochtproduktItems-'.$type->produkttype_id, // required: css class selector\r\n                'widgetItem' => '.tochtproduktItem-'.$type->produkttype_id, // required: css class\r\n                'limit' => 50, // the maximum times, an element can be cloned (default 999)\r\n                'min' => 0, // 0 or 1 (default 1)\r\n                'insertButton' => '.addTochtproduktItem-'.$type->produkttype_id, // css class\r\n                'deleteButton' => '.removeTochtproduktItem-'.$type->produkttype_id, // css class\r\n                'model' => $tochtprodukt[$type->produkttype_id][0],\r\n                'formId' => \"edittocht\",\r\n                'formFields' => [\r\n                    'produkt_id',\r\n                    'prijs',\r\n                ],\r\n        ]);    \r\n ?>       \r\n        <div class=\"containerTochtproduktItems-<?= $type->produkttype_id?> tochtproduktsection\">\r\n <?php\r\n\r\n    foreach($tochtprodukt[$type->produkttype_id] as $i => $tochtproduktItem):\r\n\r\n            // necessary for update action.\r\n            if (! $tochtproduktItem->isNewRecord) {\r\n                echo Html::activeHiddenInput($tochtproduktItem, \"[{$i}][$type->produkttype_id]tocht_id\");\r\n            }\r\n        ?>        \r\n            <div class=\"row tochtproduktItem-<?=$type->produkttype_id?>\">\r\n                <div class=\"col-md-1 text-center\">\r\n                    <button type=\"button\" class=\"removeTochtproduktItem-<?=$type->produkttype_id?> btn btn-danger btn-xs \" style=\"margin-top:5px;\"><i class=\"glyphicon glyphicon-minus\"></i></button>\r\n                </div>\r\n                <div class=\"col-md-8\">\r\n                    <?= $form->field($tochtproduktItem, \"[{$i}][$type->produkttype_id]produkt_id\")->widget(Select2::classname(), [\r\n                        'data' => ArrayHelper::map(\r\n                                    Produktdetail::find()\r\n                                    ->joinWith('produkt')\r\n                                    ->where(['=','taal_id',Taal::DEFAULT_LANG])\r\n                                    ->andWhere(['=','produkt.produkttype_id',$type->produkttype_id])\r\n                                    ->all(),\r\n                                    'produkt_id','naam'),\r\n                        'language' => 'nl',\r\n                        'options' => ['placeholder' => 'Selecteer produkt','class'=> \"produktitem\"],\r\n                        'pluginOptions' => [\r\n                                'allowClear' => true\r\n                            ],\r\n                        'size' => Select2::THEME_BOOTSTRAP,\r\n                    ])->label(false); \r\n                    ?>\r\n                </div>\r\n                <div class=\"col-md-3\">\r\n                    <?= $form->field($tochtproduktItem, \"[{$i}][$type->produkttype_id]prijs\")->textInput([\"class\"=>\"money\"])->label(false); ?>\r\n                </div>\r\n        \r\n        \r\n        </div>\r\n    <?php\r\n\r\n\r\n    \r\n    endforeach; ?>\r\n\r\n   \r\n        <div class=\"row\" id=\"insert-before-this-<?= $type->produkttype_id?>\">\r\n            <div class=\"col-md-1 text-center\">\r\n                <button type=\"button\" class=\"addTochtproduktItem-<?=$type->produkttype_id?> btn btn-success btn-xs\"><i class=\"glyphicon glyphicon-plus\"></i></button>        \r\n            </div>\r\n        </div>\r\n        \r\n    </div>\r\n    \r\n      \r\n    <?php DynamicFormWidget::end();?>`\r\n```\r\n\r\n\r\n\r\nmodel/update/X gets rendered\r\nif `'model' => $tochtprodukt[$type->produkttype_id]` is not empty and \"addItem\" is clicked, the value is duplicated, instead of creating a new item.\r\nTried to empty the selection afterInsert via different means, calling click event on the removal button of the select2 widget, setting option:selected value of it, etc...\r\n\r\nsidenote:\r\nI'm going back to a normal dropdownList for now.\r\nGetting it to work at all was such a hassle... spend hours of hacking instead of developing my app.\r\n\r\nIf you're not using select2 in dynamicform, go for it, else, skip it.\r\n"},"comment":{"url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/comments/182967256","html_url":"https://github.com/wbraganca/yii2-dynamicform/issues/126#issuecomment-182967256","issue_url":"https://api.github.com/repos/wbraganca/yii2-dynamicform/issues/126","id":182967256,"user":{"login":"kankerlijer","id":10619287,"avatar_url":"https://avatars.githubusercontent.com/u/10619287?v=3","gravatar_id":"","url":"https://api.github.com/users/kankerlijer","html_url":"https://github.com/kankerlijer","followers_url":"https://api.github.com/users/kankerlijer/followers","following_url":"https://api.github.com/users/kankerlijer/following{/other_user}","gists_url":"https://api.github.com/users/kankerlijer/gists{/gist_id}","starred_url":"https://api.github.com/users/kankerlijer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kankerlijer/subscriptions","organizations_url":"https://api.github.com/users/kankerlijer/orgs","repos_url":"https://api.github.com/users/kankerlijer/repos","events_url":"https://api.github.com/users/kankerlijer/events{/privacy}","received_events_url":"https://api.github.com/users/kankerlijer/received_events","type":"User","site_admin":false},"created_at":"2016-02-11T17:28:24Z","updated_at":"2016-02-11T17:28:24Z","body":"okay, cancel this. the issue persists when using simple dropdownlist. the value of the new inserted attribute gets duplicated when an empty value is expected.\r\n\r\nam i doing something wrong in general?"}}