0

In my view I have this code:

echo $form->select2Row($model, 'Zustelladresse', array(
            'asDropDownList' => false,
            'options' => array(
                'placeholder' => "Zustelladresse",
                'width' => '100%',
                'closeOnSelect' => true,
                'minimumInputLength'=>1,
                'initSelection' => "js:function (element, callback) {
                            var selected_data = new Object;
                            selected_data.id = '123';
                            selected_data.text = 'Test';
                            callback(selected_data);
                        }",
                'ajax' => array(
                    'url' => Yii::app()->createUrl('address/zustelladresse'),
                    'dataType' => 'json',
                    'data' => 'js:function(term,page) { if(term && term.length){ return { zustelladresse: term };} }',
                    'results' => 'js:function(data,page) { return {results: data}; }',
                ),
            )));

Created html: Output Html

Why is created only label and hidden input?

toredo
  • 51
  • 3
  • Is the select2 js and css being loaded? – topher Dec 30 '13 at 17:13
  • Thanks topher, the problem was that I am rendering as a partial $this->renderPartial('_edit', array( 'model' => $model )); but the correct code is $this->renderPartial('_edit', array( 'model' => $model ), false, true); – toredo Jan 09 '14 at 08:59

1 Answers1

0

YiiBooster widgets are quite tricky to debug, if anything is wrong they just don't show. If you still need the answer, I successfully displayed a select2 widget with this code:

$form->select2Row($model, 'attribute_name', array(
   'data' => array('1'=>'value1,'2'=>'value2'),
   'htmlOptions'=>array(
     'style' => 'width:600px',
     'multiple' => true,
   ),
   'options'=>array('placeholder'=>'Please make a selection'),
));

I'd suggest you to start from this code and add up your options one by one, and see if anything breaks.

Maxxer
  • 1,038
  • 1
  • 18
  • 37