How can an item be added when it does not exist in the Kartik Select2 widget.
For example when I have an order and want to choose a customer, while typing and when the customer does not exist,
A question should popup asking if a new customer should be created.
When yes has been choosen, a new insert customer form should popup, after creating the new customer and closing the popup, the new customer should be selected in the Select2 Widget.
Here’s the code to select a customer.
In views\orders\_form:
<?php use kartik\widgets\Select2;
// usage with ActiveForm and model
echo $form->field($model, 'customer_id')->widget(Select2::classname(), [
'language' => 'nl',
'data' => ArrayHelper::map(\app\models\Customers::find()->orderBy('customername')->all(), 'id', 'customername'),
'options' => ['placeholder' => 'Select a name ...'],
'pluginOptions' => [
'allowClear' => true
],
]);?>