Typeahead Field With Option And Value Like Select Field

I am trying to migrate Yii1.X to Yii2

What are the options in Yii2 to create ajax dropdownlist?

What is ajax dropdownlist?

For ex:

In Yii1. I have used select2 extension like below to populate a dropdown

<?php echo $form->select2Row($model, 'country_name', array(

'asDropDownList' => false,

'options' => array(

'closeOnSelect' => false,

'placeholder' => 'Select Country',

'allowClear' => true,

'ajax' => array(

'url' => CController::createUrl('user/ajaxgetcountry'),

'dataType' => 'json',

'data' => 'js:function(term,page) { return {q: term, page_limit: 10, page: page}; }',

'results' => 'js:function(data,page) { return {results: data}; }',




But I want to know how to migrate it to Yii2

Well, you can either port it to Yii2 or write some custom JavaScript.


I have found that We can use typeahead.js to work smootholy with all kinds ajax calls in yii.

but typeahead is not like select field.

When I select an option from displayed options, I actually want to select its actual value like SELECT field.

Does any one know how to do it?