S
S
shmelfrol2021-07-16 12:13:41
Yii
shmelfrol, 2021-07-16 12:13:41

How to make a drop down list of cities in yii2?

Hello. there is a table of cities. How to implement input with a datalist - so that when you enter a value in the field, the city is displayed in the list
I did this - but options do not work like that

Convert the city object to an array

$items = ArrayHelper::map($cities,'id','name');
 

<?= $form->field($search, 'fullname', ['options'=>['list'=>'datalist1']]); ?>
            <datalist id="datalist1">
        <?php foreach($items as $city): ?>
            <option value="<?php echo $city?>">

            <?php endforeach; ?>
            </datalist>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vilinyh, 2021-07-16
@vilinyh

https://github.com/kartik-v/yii2-widget-select2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question