2amigos / yii2-selectize-widget

Selectize From Brian Reavis Yii2 Widget
Other
73 stars 41 forks source link

When using numeric value as option value, selectize resets them #34

Closed sachya closed 7 years ago

sachya commented 7 years ago

Consider array array(2) { [1]=> string(10) "mh18aj6209" [2]=> string(4) "MH45" } Selectize actually presents this as follows array(2) { [0]=> string(10) "mh18aj6209" [1]=> string(4) "MH45" }

It is a big problem for me, as i primarily work keys as db primary key records. Please help to rectify this error. The code i used:

    <?= $form->field($model, 'vehicle_id')->widget(Selectize::className(),
 [
                'options'=>[
                  'placeholder'=>'Select Vehicle for trip'
                ], 
                'items'=>array_merge([''=>''], app\models\Vehicle::getvehiclefortrip()),
                'clientOptions' => [
                ],
            ]) ?>

I tried using regular selectize js on codepen and it works there. Strange issue.

tonydspaniard commented 7 years ago

@sachya we have no issues at all with that. what is the getVehicleforTrip function contents?

sachya commented 7 years ago

Hi tony, the big problem is with function array_merge, it starts key value with 1. So array(2) { [1]=> string(10) "mh18aj6209" [2]=> string(4) "MH45" }

becomes

array(2) { [0]=> string(10) "mh18aj6209" [1]=> string(4) "MH45" }

if we use alphabet or non-numericals it works just fine, but fumble over numeric keys.

The solution i got: 'items' => [''=>'']+app\models\Vehicle::getvehiclefortrip()

Keep this area tagged as i got the array merge solution from one of your sorted issues. Meanwhile, enjoying selectize, Thank You

tonydspaniard commented 7 years ago

We cannot fight against PHP's defaults behavior. Thanks for the hint.