kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 175 forks source link

Adding new attribute inside ajax load select2 #359

Open RamiRayya opened 6 years ago

RamiRayya commented 6 years ago
                <?= $form->field($detail, "[{$i}]product_id")->widget(Select2::classname(), [
                      'initValueText' =>  $productDesc, // set the initial
                      'options' => ['placeholder' => 'Search for a Salesman ...' , 'id' => 'sem'],
                      'pluginOptions' => [
                          'allowClear' => true,
                          'minimumInputLength' => 3,
                          'language' => [
                              'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
                          ],
                          'ajax' => [
                              'url' => $productUrl,
                              'dataType' => 'json',
                              'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                          ],
                          'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                          'templateResult' => new JsExpression('function(product) { return product.text; }'),
                          'templateSelection' => new JsExpression('function (product) { return product.text; }'),
                      ],
                    ]);
                ?>
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/59858390-adding-new-attribute-inside-ajax-load-select2?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github).