kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

why use condition for $emptyPH is true when not empty $key #303

Closed idencial closed 4 years ago

idencial commented 4 years ago

I updated to the latest version of the module and have problem with default values (when edit some object) for the case when using ajax

That is, I have a non-empty value initValueText, as well as a non-empty value for the field where it is used select2, but when I opened the edit page with this select2 field, no default value selected

i found a problem It turned out that the problem is in this line of code $this->data = $multiple ? array_combine((array)$key, (array)$val) : (($emptyPH && $key !== '') ? [$key => $val] : []); The problem is that the condition is $emptyPH must be true That is, the initial values will be substituted only if in options are not specified placeholder I temporarily solved the problem like this if (empty($place_name)) { $select2_place_options = ['placeholder' => 'Choose a place ...', 'multiple' => false]; } else { $select2_place_options = ['multiple' => false]; } Ie when I have a non-empty value for 'initValueText' => $place_name, I dont use placeholder in options Ie I have a question, why use condition for $emptyPH is true when not empty $key?

kartik-v commented 4 years ago

Check if it is resolved with the latest fix? Else will reopen.

SHI1989 commented 4 years ago

In packagist the last available version is 2.1.6. Please refresh to 2.1.7. Thanks.

kartik-v commented 4 years ago

The latest release is not tagged yet (pending confirmations from few) - once it is tagged it will appear on packagist. Till then you can use the code from dev-master