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

Yii2 Select2 Always Showing Placeholder Instead of Database Values #363

Open
abdelilahdahdahi opened this issue Jan 7, 2024 · 0 comments

Comments

@abdelilahdahdahi
Copy link

I have a problem with my Yii2 Select2 field because it's not retrieving inserted values from the database, showing the placeholder all the time. I tried using a method to retrieve the inserted values from the database and put them in the 'value' field attribute, but when saving the form they resulted in duplicate entries, meaning that the real records are still in the field but kinda hidden. What can I do about it to show the inserted values in the Select2?

This is the form field

<div class="col-md-4">
    <?php $utenti = ArrayHelper::map(Profile::getListUtentiAttivi(), 'user_id', 'name');
        echo $form->field($model, 'assegnazione', ['options' => [
            'class' => 'form-group form-group-default form-group-default-select2']])
                ->widget(Select2::className(), [
                    'data' => $utenti,
                    'options' => [
                        'placeholder' => 'Sottoscrittori...',
                        'multiple' => true,
                    ],
                    'pluginOptions' => [
                        'allowClear' => true,
                        'multiple' => true,
                    ],
                    'theme' => Select2::THEME_DEFAULT,
        ])->label('Sottoscrittori');?>
</div>

I tried adding inside options[ ] something like 'value' => methodToGetInsertedValues() but as I said before, it gives error of duplicate entries

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