<?= $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).