Hi,
i fiddle a while with this problem.
i want to use a form-field with an id of an related table, in this case order - customer. when i use this code with a string form-field, its working.
but i want an autocomplete field wher i see two field of the related table, select on item and get the id in my form-field.
in this code i get no suggesttion list displayes, the source list is displayed.
i tried for source:
'source' => ArrayHelper::getColumn($data, 'name'),
and
'source' => ArrayHelper::getColumn($data, 'id'),
and
'source' => $data,
this is working, but not what i want.
<?= $form->field($model, 'name')->widget(AutoComplete::classname(), [
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'minLength'=>'0',
],
]) ?>
use yii\jui\AutoComplete;
use yii\web\JsExpression;
$data = Customer::find()
->select(['CONCAT(nachname," ",vorname) as name','CONCAT(nachname," ",vorname) as value', 'id as id'])->distinct()
->orderBy(['name' => SORT_ASC])
->asArray()
->all();
<?= $form->field($model, 'customer_id')->widget(AutoComplete::classname(), [
'clientOptions' => [
'source' => ArrayHelper::getColumn($data, 'name'),//$data,
'select' => new JsExpression("function( event, ui ) {
$('#model-order-cust').val(ui.item.id);
}"),
'autoFill'=>true,
'minLength'=>'0',
],
]) ?>
any Ideas? Hope to map show a string list an set an id to a form field? is this possible?