I want to create an Editable Dropdown in Yii using the HTML Input List Attribute.
I notice the Yii ActiveField does not provide an option for Input List. Any suggestions on how to implement this?
I want to create an Editable Dropdown in Yii using the HTML Input List Attribute.
I notice the Yii ActiveField does not provide an option for Input List. Any suggestions on how to implement this?
This turned out to be rather simple. Here is the solution:
<?php
use yii\bootstrap4\ActiveForm;
?>
...
<?= $form->field($model, 'majorcity')->textInput(['list' => 'datalistOptions']) ?>
...
<datalist id="datalistOptions">
<option value="San Francisco">
<option value="New York">
<option value="Seattle">
<option value="Los Angeles">
<option value="Chicago">
</datalist>
You can also just use input instead of textInput. Optionall add additional classes or placeholder text as below:
<?= $form->field($model, 'majorcity')->input(Null, ['class' => 'form-control w-50', 'list' => 'datalistOptions', 'placeholder'=>'']) ?>
Using text is probably better I think.