Hello. Please tell me how you can add new option elements to select. I'm interested in saving. How it should be on the server side.

echo $form->field($model, 'id_serial_number')->widget(Select2::classname(), [ 'options' => [ 'placeholder' => 'Поиск серийного номера ...', 'id' => 'MySelecet2', ], 'pluginOptions' => [ 'tags' => true, 'allowClear' => true, 'minimumInputLength' => 3, //'language' => 'ru', 'language' => [ 'noResults' => new JsExpression('function () { return "<button type=\"button\" id=\"button\" class=\"btn btn btn-success btn-xs\" data-url=\"' . Url::to(['catalog_serial_number/ajax-create']) . '\">Добавить</button>"; }'), ], 'ajax' => [ 'url' => Url::to(['catalog_serial_number/ajax-list']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }'), ], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function(name) { return name.text; }'), 'templateSelection' => new JsExpression('function (name) { return name.text; }'), ], ]); 

There is such a code that forms Select2. When you try to enter any value, the values ​​are searched through ajax on the server side and when this value is selected, the option tag will contain the value parameter with the id of the element that was found. If no values ​​are found, a new option tag will be added with the value parameter that were entered into the input, how do I determine on the server side and process the subsequent saving of data? If the user selects any element, for example, the value will contain id 102 but is not excluded and such an option is that the user can simply enter 102 and the data will then not be correct.

    0