Closed omsi668 closed 4 years ago
The similar issue after update: multiple=>false + ajax: can't preset value by initValueText while pluginOptions['placeholder'] exists. that placeholder should be dropped at all or
'placeholder' => !$model->gallery_id ? 'Select item...' : null,
Anyway something has been broken...
Check if it is resolved with the latest fix? Else will reopen.
Seems it works.
Hello,
I tried the master branch and the bugs seems to be still there (i still see empty placeholders)
I pushed in a small update...
@omsi668 can you please share your configuration and code sample to reproduce your issue? Currently cannot reproduce your use case.
data
property setting in Select2
widget for your use case - is it empty, has values or what is it when you see the issue above?placeholder
setting?Hello,
With this latest fix it seems to work, i don't manage to make it bug again thank you.
Just for information if you want to build a test case i'll still answer your questions as much as possible :
$skills = [];
if (is_array($searchModel->skills)) {
foreach ($searchModel->skills as $skillId) {
$skills[$skillId] = Skills::findOne($skillId)->getLabel();
}
}
<select id="matching-skills" class="form-control select2-hidden-accessible" name="Matching[skills][]" multiple="" size="4" data-s2-options="s2options_c4acac00" data-krajee-select2="select2_bcacd2b6" style="width: 1px; height: 1px; visibility: hidden;" data-select2-id="matching-skills" tabindex="-1" aria-hidden="true">
- This is obviously with dev-master 58d9a32
Thank you
Prerequisites
master
branch of yii2-widget-select2.Steps to reproduce the issue
Hello,
When I updated the plugin from 2.1.4 to 2.1.6 I have a bunch of fields not working anymore and can't find a proper solution to it (I then expect it's a bug). The context is a page with 3 Select2 plugins, all optional, all with multiple and Ajax. Everything was working fine with 2.1.4.
This is the code of one of them :
Select2::widget([ 'data' => $skills, 'options' => [ 'multiple' => true, 'class' => 'form-control', ], 'model' => $searchModel, 'attribute' => 'skills', 'pluginOptions' => [ 'minimumInputLength' => 2, 'ajax' => [ 'url' => Yii::$app->urlManager->createUrl(['/ajax/find-skill']), 'processResults' => new JsExpression(AjaxController::processResultsFindJs()), ], 'language' => [ 'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"), ], ], ]);
$skills is populated with an array of preselected values if you come to the form already populated.
This form will populate a searchFilter where $skills is declared as an attribute of searchFilter as public $skills = [];
No specific rules are set to skills attribute except "safe"
Then we populate the skills attribute of the searchFilter with the load() method. (I wrote everything but in the end this is just classic search, no extra JS, no fancy method)
The problem is that, if I don't fill any skill in my search, select2 will still send an empty string, and then populate the field with an empty token (see attachment).
How to avoid that?
Thank you
Libraries
Isolating the problem