Kartik Select2 use results to display Data


i have the below.

What i would like to do is after selection from drop down display some data from a related table.


<?php $form = ActiveForm::begin(); ?>
    <?= $model->isNewRecord ? 

     $form->field($model, 'quote_id') ->textInput(['readonly' => true, 'value' => $id])
     $form->field($model, 'quote_id') ->textInput()

    <?=  $form->field($model, 'part_id')->widget(Select2::classname(), [
    'name' => 'Partselect',
   'data' => $items,
   'options' => ['placeholder' => 'Select a item ...', 'attribute' => 'category','id'=>'id_select'],
    'pluginOptions' => [
            'allowClear' => true
    'pluginEvents' => [
        "change" => 'function(e) {
            var part_id = $(this).val();

]); ?>

/// Field to show related Data


$modelp = Parts::findOne('part_id');

any ideas?

jquery provides a helper which makes it easy to load content into a div

function(e) {
	var part_id = $(this).val();
	$("#testVal").load("controller/action?part_id=" + part_id);

in your controller you can a send a value back or even render a view

$modelp = Parts::findOne($_GET['part_id']);
return $modelp->part_id;

Thank you.

when you say load content into a DIV quite how does this work?

When i change the controller as described i believe the $_GET try to get the ID from the URL? but we haven’t posted this ID to the URL?

Thank you