Answer the question
In order to leave comments, you need to log in
How to make Selectize yii2 work?
Good afternoon. I wanted to make tags for the article, like on toaster.ru using the Selectize and Taggable plugin from dosamigos.
I indicate in the form
<?php echo
$form->field($model, 'content')->widget(Selectize::className(), [
// calls an action that returns a JSON object with matched
// tags
'url' => Url::toRoute(['list']),
'options' => ['class' => 'form-control'],
'clientOptions' => [
'plugins' => ['remove_button'],
'valueField' => 'name',
'labelField' => 'name',
'searchField' => ['name'],
'create' => true,
],
])->hint('Use commas to separate tags')
?>
public function actionList($query)
{
$models = Tag::findAllByName($query);
var_dump($models);
$items = [];
foreach ($models as $model) {
$items[] = ['name' => $model->name];
}
// We know we can use ContentNegotiator filter
// this way is easier to show you here :)
Yii::$app->response->format = Response::FORMAT_JSON;
return $items;
}
$models = Tag::findAllByName($query);
works. How to dig out the error?
Answer the question
In order to leave comments, you need to log in
Well, for starters, see if the ajax request goes to this action. if not, look in the console for errors.
You need to write 'loadUrl' => Url::toRoute(['list']) instead of 'url' => Url::toRoute(['list'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question