<?php $form = ActiveForm::begin(['id' => 'product-replacement-form']); ?>
<div class="row mb-3">
-
- <div class="col-6">
+ <div class="col-6">
<?= $form->field($model, 'guid')->widget(Select2::class, [
'options' => ['placeholder' => 'Выберите товар...'],
results: $.map(data.items, function(item) {
return {
id: item.id,
- text: item.text
+ text: item.text
};
})
};
<div class="row">
- <div id="guid-replacement-container" class="col-6">
+ <div id="guid-replacement-container" class="col-6">
<?= $form->field($model, 'guid_replacement[]')->widget(Select2::class, [
'options' => ['placeholder' => 'Выберите замену...', 'class' => 'guid-replacement-select'],
'pluginOptions' => [
'ajax' => [
'url' => \yii\helpers\Url::to(['/crud/product1c-replacement/search']),
'dataType' => 'json',
- 'data' => new JsExpression('function(params) {
+ 'data' => new JsExpression('function(params) {
var exclude = [];
- exclude.push($("#product1creplacement-guid").val());
+ exclude.push($("#product1creplacement-guid").val());
$(".guid-replacement-select").each(function() {
if ($(this).val()) {
exclude.push($(this).val());
return {
q: params.term,
exclude: exclude.join(","),
- guid: $("#guid-select").val()
+ guid: $("#guid-select").val()
};
}'),
'processResults' => new JsExpression('function(data) {
],
],
]) ?>
-
- </div>
+ </div>
</div>
<!-- Кнопка добавления нового Select2 -->
<?php $form = ActiveForm::begin(['id' => 'product-replacement-form']); ?>
- <!-- Скрытое поле GUID -->
+
<?= Html::activeHiddenInput($model, 'guid', ['id' => 'guid-select']) ?>
- <!-- --><?php /*= $form->field($model, 'guid')->widget(Select2::class, [
- 'value' => $model->id,
- 'options' => ['placeholder' => 'Выберите товар...', 'id' => 'product-replacement-form-guid'],
- 'pluginOptions' => [
- 'allowClear' => true,
- 'minimumInputLength' => 1,
- 'ajax' => [
- 'url' => \yii\helpers\Url::to(['/crud/product1c-replacement/search']),
- 'dataType' => 'json',
- 'data' => new JsExpression('function(params) { return {q:params.term}; }'),
- 'processResults' => new JsExpression('function(data) {
- return {
- results: $.map(data.items, function(item) {
- return {
- id: item.id,
- text: item.text
- };
- })
- };
- }'),
- ],
- ],
- ]) */?>
+
<div class="row">
<div id="guid-replacement-container" class="col-6">
'ajax' => [
'url' => \yii\helpers\Url::to(['/crud/product1c-replacement/search']),
'dataType' => 'json',
- 'data' => new JsExpression('function(params) {
+ 'data' => new JsExpression('function(params) {
var exclude = [];
exclude.push($("#guid-select").val());
$(".guid-replacement-select").each(function() {
});
return {
q: params.term,
- exclude: exclude.join(","),
-
+ exclude: exclude.join(","),
};
}'),
'processResults' => new JsExpression('function(data) {
- return {
- results: $.map(data.items, function(item) {
- return {
- id: item.id,
- text: item.text
- };
- })
- };
- }'),
+ return {
+ results: $.map(data.items, function(item) {
+ return {
+ id: item.id,
+ text: item.text
+ };
+ })
+ };
+ }'),
],
'initSelection' => new JsExpression('function (element, callback) {
- var data = {id: ' . json_encode($replacement->guid_replacement) . ', text: ' . json_encode($replacementName) . '};
- callback(data);
- }'),
+ var data = {id: ' . json_encode($replacement->guid_replacement) . ', text: ' . json_encode($replacementName) . '};
+ callback(data);
+ }'),
],
]) ?>
<button type="button"
class="btn btn-danger delete-guid-replacement btn-remove"
-
data-url="<?= \yii\helpers\Url::to(['/crud/product1c-replacement/delete', 'id' => $replacement->id]) ?>"
- style="position: absolute; right: -40px; top:33%; width:auto;">
- ×
- </button>
+ style="position: absolute; right: -40px; top:33%; width:auto;">×</button>
</div>
<?php endforeach; ?>