A
A
Alexander Pantyukhov2016-06-21 07:31:28
JavaScript
Alexander Pantyukhov, 2016-06-21 07:31:28

How to find out which event is fired when clicking on the select2 popup?

Good day to all!
3 DepDrops are created per page with type DepDrop::TYPE_SELECT2 and they are multiselect. The second and third depend on the first. When you select something from the first DepDrop on the page, then the required list for selection is loaded into the other two, and when you score using JS like $("#mark").select2('val',[2,1]) (where mark is the id of the first DepDrop), then the lists are not loaded. Please tell me what events need to be repeated to load the lists?
Code of the first and second DepDrop:

$form->field($modelForm, 'market',['showLabels' => false])->widget(Select2::classname(), [
            'data' => $modelForm->selectMarket,
            'theme' => Select2::THEME_BOOTSTRAP,
            'options' => [
                'placeholder' => 'Select Market...',
                'id' => 'market',
                'multiple' => true,
            ],
            'pluginOptions' => [
                'width' => '280px',
                'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                'templateResult' => new JsExpression('formatMarket'),
                'templateSelection' => new JsExpression('formatMarket'),
            ]
        ]);

$form->field($modelForm, 'marketAccount',['showLabels' => false])->widget(DepDrop::classname(), [
                'type' => DepDrop::TYPE_SELECT2,
                'data' => is_array($modelForm->marketAccount)? [] :[$modelForm->marketAccount=>''],
                'options' =>['id'=>'marketAccount','multiple' => true],
                'select2Options' => [
                    'pluginOptions' => ['width' => '230px'],
                    'theme' => Select2::THEME_BOOTSTRAP,
                ],
                'pluginOptions' => [
                    'initialize' => true,
                    'initDepends' => ['market','proxyRegion'],
                    'allowClear' => true,
                    'placeholder' => 'All',
                    'depends' => ['market','proxyRegion'],
                    'url' => Url::to(['application/app-acc-subcat']),
                    'loadingText' => 'All',
                    'params'=>['marketAccountIdHidden']
                ],
                'pluginEvents'=>[
                    "depdrop.change"=>"function() { $('#marketAccount').select2('val',".json_encode($modelForm->marketAccount)."); }",
                    "select2:selecting"=>"function() {
                    var marketAccount = $('#marketAccount');
                     var array = marketAccount.select2('val');
                     if(array == null ||typeof array === 'string'){
                        return;
                     }
                     var position = array.indexOf('');
                     if(position !== -1){
                     array.splice(position, 1);
                     marketAccount.select2('val',array);
                     }
                      }",
                ]
            ]
        );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-06-21
@vshvydky

'depends' => ['market,'proxyRegion'],
doesn't bother?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question