Answer the question
In order to leave comments, you need to log in
How to limit the number of output items in yii2 autocomplete?
There is an autocomplete widget on the page
<?= $form->field($model,'city')->label(false)->widget(\yii\jui\AutoComplete::className(),[
'clientOptions' => [
'source' => ArrayHelper::getColumn(\app\models\City::find()->select('city_name_ru')->all(),'city_name_ru'),
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Город',
'value' => $city
]
])?>
Answer the question
In order to leave comments, you need to log in
what do you mean by
limit the number of output results
'clientOptions' => [
'minLength' => 3
],
.ui-autocomplete {
max-height: 100px;
verflow-y: auto;
overflow-x: hidden;
}
If the method proposed by Maxim Fedorov does not suit you, then you can also try this stackoverflow.com/a/7617637/4828205
'clientOptions' => [
'source' => new \yii\web\JsExpression("function(request, response) {
var results = $.ui.autocomplete.filter(myarray, request.term);
response(results.slice(0, 10));
}"
]
where you really have to pervert with a request to the database from the js function. but this can be implemented with using ajax, the widget does the same
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question