2012-12-04 48 views
1

我是Yii的新手framework.i發佈了很多次,但沒有回覆。 我在cjuidatepicker小部件的註冊表單中有日期字段。 這個小部件在靜態頁面中運行良好,但是當我以彈出窗體的形式使用它時,此小部件不會顯示。yii框架中的cjuidatepicker小部件

任何意見,將不勝感激。

一個鏈接,打開一個彈出的對話框,它的代碼是在這裏。

<?php 
    echo CHtml::link('Add Client ', "", 
     array(
      'style'=>'cursor: pointer; font-size:20px; text-decoration: underline;', 
      'onclick'=>"{addclient(); $('#dialogclient').dialog('open');}" 
     ) 
    ); 
?> 

cjuidatepicker插件代碼:

<?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
    'model'=>$model, 
    'value'=>'p_end_date', 
    'attribute'=>'p_end_date', 
    // additional JavaScript options for the date picker plugin 
    'options'=>array(
     'showAnim'=>'fold', 
     'dateFormat'=>'yy-mm-dd', 
    ), 
    'htmlOptions'=>array(
     'style'=>'height:20px;',     
    ), 
)); 

修訂編輯:用於呈現/使用URL

<script type="text/javascript"> 
    // here is the magic 
function addclient() 
{ 
<?php echo CHtml::ajax(array(
     **'url'=>array('client/create'),** 
     'data'=> "js:$(this).serialize()", 
     'type'=>'post', 
     'dataType'=>'json', 
     'success'=>"function(data) 
     { 
      if (data.status == 'failure') 
      { 
       $('#dialogclient div.divForForm').html(data.div); 
         // Here is the trick: on submit-> once again this function! 
       $('#dialogclient div.divForForm form').submit(addclient); 
      } 
      else 
      { 
       $('#dialogclient div.divForForm').html(data.div); 
       setTimeout(\"$('#dialogclient').dialog('close') \",3000); 
      } 

     } ", 
     )) 
    ?>; 
    return false; 

     } 

    </script> 

Actioncreate()控制器CODE

  public function actionCreate() 
      { 
      $model=new client; 

     // Uncomment the following line if AJAX validation is needed 
     // $this->performAjaxValidation($model); 

    if(isset($_POST['client'])) 
    { 
     $model->attributes=$_POST['client']; 


     if($model->save()) 
     { 
      if (Yii::app()->request->isAjaxRequest) 
      { 
       echo CJSON::encode(array(
        'status'=>'success', 
        'div'=>"Client successfully added" 
        )); 
       exit;    
      } 
      else 
       $this->redirect(array('view','id'=>$model->id)); 
     } 
    } 

    if (Yii::app()->request->isAjaxRequest) 
    { 
     echo CJSON::encode(array(
      'status'=>'failure', 
      'div'=>$this->renderPartial('_form', array('model'=>$model), true))); 

     exit;    
    } 
    else 
     $this->render('create',array('model'=>$model,)); 
} 
打開_from.php 代碼

回答

2

我猜想是cjuidatepicker小部件的導入代碼不在新彈出窗口中。當彈出窗口打開時,轉到源代碼並查看是否所有的js導入都在那裏?

+0

我怎麼能檢查JS進口...? –

+0

你可以在這裏添加彈出窗口的源代碼嗎?所以很容易找出bug的位置。 – Mujahid

+0

@Muhahid ... PLZ看到我的新的編輯我的問題actioncreate()...謝謝 –