M
M
microf2014-10-25 08:35:09
Yii
microf, 2014-10-25 08:35:09

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')
                        ?>

In the controller
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;
}

But the method in the controller is not called in any way. Doesn't throw any error, nothing. You can change the url in the widget - nothing happens either.
$models = Tag::findAllByName($query);works. How to dig out the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Zelenin, 2014-10-25
@microf

Well, for starters, see if the ajax request goes to this action. if not, look in the console for errors.

H
herrzenlemer, 2015-07-02
@herrzenlemer

You need to write 'loadUrl' => Url::toRoute(['list']) instead of 'url' => Url::toRoute(['list'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question