1

Trying to load a block with a datepicker from a view.. but it loads only the textfield without datepicking feature. What am I doing wrong?

The create view

<?php echo $form->dropDownList($model,'operation_type',CHtml::listData(OperationType::model()->findAll(),
'id','name'),array(
    'class'=>'span3',
    'empty'=>'----- Type -----',
    'id'=>'idOpType',
    'ajax'=>array(
        'type'=>'POST',
        'url'=>CController::createUrl('operations/meta'),
        //'dataType'=>'json',
        'data'=>array('idOpType'=>'js:this.options[this.selectedIndex].innerHTML'),
        'success'=>'function(data){
            $("#opTypeBlock").html(data);
        }',
    ),
)); ?>

The Controller Action

public function actionMeta(){
        $data= new OperationsMeta();
        $this->renderPartial('_meta',array('model'=>$data));
    }

The view I am trying to load

<p>Select due date</p>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'attribute'=>'param',
    'options'=>array(
        'showAnim'=>'fold',
    ),
    'model'=>$model,
    'htmlOptions'=>array(
        'style'=>'height:20px;',
        'class'=>'inline',
        'id'=>'datepickerOpType',
    ),
));
?>
Vit Kos
  • 5,535
  • 5
  • 44
  • 58

2 Answers2

2

Try

$this->renderPartial('_meta',array('model'=>$data), false, true);

so it loads JS files.

Valdas
  • 1,074
  • 13
  • 20
  • @Vit try the above code, if problem exist lookout this answer [include-css-javascript-file-in-yii-framework](http://stackoverflow.com/questions/1998449/include-css-javascript-file-in-yii-framework/11558722#11558722) – Onkar Janwa Aug 29 '12 at 12:18
  • This helped, thank you. Can you explain me what are the two additional parameters passed to the renderPartial? – Vit Kos Aug 29 '12 at 12:25
  • You can read it at documentation: http://www.yiiframework.com/doc/api/1.1/CController – Valdas Aug 29 '12 at 12:28
0

Use renderAjax() which injects into the rendering result with JS/CSS scripts and files which are registered with the view, as stated here.

mustafa.yavuz
  • 1,274
  • 2
  • 21
  • 40