Answer the question
In order to leave comments, you need to log in
Why is the field filled with value and not label when using the Autocomplete plugin?
Good afternoon. I use yii/jui/Autocomplete.
<?= AutoComplete::widget([
'name' => 'client',
'id' => 'client-find',
'options' => [
'class' => 'form-control',
],
'clientOptions' => [
'source' => MemberUser::find()
->select(['concat( lastname, " ", firstname ) as label', 'id as value'])
->asArray()
->all(),
'autoFill' => true,
'minLength' => 2,
'select' => new yii\web\JsExpression("function( event, ui ) {
console.log(ui.item);
document.getElementById('eventsuser-client').value = ui.item.value;
document.getElementById('client-find').value = ui.item.label;
}")
]
]); ?>
Answer the question
In order to leave comments, you need to log in
Everything. Understood. Corrected version:
<?= AutoComplete::widget([
'name' => 'client',
'id' => 'client-find',
'options' => [
'class' => 'form-control',
],
'clientOptions' => [
'source' => MemberUser::find()
->select(['concat( lastname, " ", firstname ) as label', 'concat( lastname, " ", firstname ) as value', 'id as id'])
->asArray()
->all(),
'autoFill' => false,
'minLength' => 2,
'select' => new yii\web\JsExpression("function( event, ui ) {
console.log(ui.item);
document.getElementById('eventsuser-client').value = ui.item.id;
document.getElementById('client-find').value = ui.item.label;
}")
]
]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question