Hi everyone i’m trying to return de id from a select2 widget and also i’m using an array map to search my model, what i need to do, it’s return the selected id value, because i’m using that id to do another search, but i’m dont know how do it, can you help me thanks.
Thanks alirz23 i can see the id value from select2, but i dont know how to pass the id value, and use it on my search:
$modelsplantilla = Plantilla::find()->where([‘id_padre’ => $id_padre])->orderBy(‘id_plantilla’)->all();
where id_plantilla = id returned from selected value
If you want to dynamically create table in the same view as your select element you should get ID from select2 widget as alirz23 proposed. Then run $.ajax call with url of controller action where you get requested Plantilla models. Controller action injects these models to a view where is the HTML code of table you want to create. And this is returned by controller as response to AJAX call. Callback function inserts this HTML code to the view where the form is. So something like this:
$('#select_input_id').on("change", function (e) {
var id =$(this).val();
$.get('url/of/controller/action',{id: id}, function(data){
$('#newTable').html(data);
});
});
controller:
public function actionTable($id_padre)
{
$modelsplantilla = Plantilla::find()->where(['id_padre' => $id_padre])->orderBy('id_plantilla')->all();
return $this->renderAjax('_table',[
'model' => $modelsplantilla,
]);
}
and also don’t forget to create view file _table where you write the code to generate table from $modelsplantilla