Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select2 multiple return saved values #360

Open
TomaIvanovTomov opened this issue Apr 15, 2018 · 0 comments
Open

Select2 multiple return saved values #360

TomaIvanovTomov opened this issue Apr 15, 2018 · 0 comments

Comments

@TomaIvanovTomov
Copy link

TomaIvanovTomov commented Apr 15, 2018

Trying to return saved values in the field on update scenario but nothing show. What I am doing is

public static function getAllSelectedCategoriesSelect2()
    {
        $categories = (new Query())
            ->select(['page.id', 'pageLang.title'])
            ->from('page')
            ->leftJoin('pageLang', 'page.id=pageLang.page_id')
            ->rightJoin('attribute_category', 'page.id=attribute_category.category_id')
            ->where('pageLang.language=:lang',[':lang' => Yii::$app->language])
            ->all();

        return ArrayHelper::map($categories, 'id', 'title');
    }

and passing the result to the value property of the widget like so

Select2::widget([
                            'name' => 'categories',
                            'value' => Attribute::getAllSelectedCategoriesSelect2(),
                            'data' => Attribute::getAllCategoriesSelect2(),
                            'options' => [
                                'multiple' => true,
                                'placeholder' => Yii::t('app', 'Select categories'),
                                'allowClear' => true
                            ],
                            'pluginOptions' => [
                                'tags' => true,
                            ]
                        ])

The result from this is empty field. What am I missing ? Thank you in advance!


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant