I Have use Typeahead’s Kartik
but i render the widget via ajax
and the js script not sending to my view (_form.php)
_form.php
<div class="divForTypeahead"></div>
<?=
Html::a('Add Widget', NULL ,
['
id' => 'addWidget',
'onclick' => 'addWidget();'
]) ?>
<script type="text/javascript" >
function addWidget()
{
$.ajax({
'url':'\\myController\\add-widget',
'data': $(this).serialize(),
'type':'post',
'dataType':'json',
'success':function(data)
{
$('div.divForTypeahead').html(data.div);
},
});
}
</script>
_addTypeAhead.php
<?= kartik\widgets\Typeahead::widget([
'name' => 'state_10',
'dataset' => [
[
'prefetch' => '/product/product-list',
]
]
]);
?>
myController.php
public function actionAddWidget()
{
if (Yii::$app->request->isAjax) {
return \yii\helpers\Json::encode([
'div' => $this->renderPartial('_addTypeAhead')
]);
}
}
when i click "Add Widget"
<div class="divForTypeahead"></div> <-- html will update, but jquery is not runinng