В представлении:
Код: Выделить всё
<?= $form->field($model, 'coauthors')->widget(MultipleInput::class, [
'min' => 1,
'max' => 5,
'allowEmptyList' => false,
'rendererClass' => \unclead\multipleinput\renderers\ListRenderer::className(),
'extraButtons' => function ($model, $index, $context) {
return '<span class="unclead_span"><a href="#" onclick="return moveChoiceTo(this, -1);">↑</a>
<a href="#" onclick="return moveChoiceTo(this, 1);">↓</a></span>';
},
'columns' => [
[
'name' => 'coauthors',
'title' => Module::t('module','COAUTHORS'),
'type' => Typeahead::className(),
'options' => [
'pluginOptions' => ['highlight' => true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
'remote' => [
'url' => Url::to(['/user/author/authorslist']) . '?q=%QUERY',
'wildcard' => '%QUERY'
],
'templates' => [
'notFound' => '<div class="text-danger" style="padding:0 8px">'.Module::t('module','AUTHORS_NOTFOUND').' '.Html::a(Module::t('module','ADD_AUTHOR'),['#'],['id'=>'modalauthor','data-url'=>Url::to('/user/author/coauthorcreate')]).'</div>',
]
]
],
],
],
],
])->label(false); ?>
Код: Выделить всё
public function actionAuthorslist($q = null)
{
$authors = Author::find()
->select(['id','concat(secondname, " ",firstname, " ",middlename) as value'])
->filterWhere(['or',['like', 'secondname', $q],['like', 'firstname', $q],['like', 'middlename', $q]])
->asArray()
->all();
$out = [];
foreach ($authors as $author) {
$out[$author['id']] = ['value' => $author['value']];
}
return Json::encode($out);
}