2015-11-03 29 views
0

我有一個窗體中的組合框。根據組合中選定的值,必須在datepicker中更改日期的值。如何執行此操作? 代碼是這樣的:更改datepicker中的值在選擇組合值中的yii

<div class="row col2"> 
<?php $records = CHtml::listData(CodeValue::model()->findAll(array('order' => 'code_lbl','condition'=>"code_type= 'visit_type'")), 'code_id', 'code_lbl');?> 
    <?php echo $form->labelEx($model,'visit_type'); ?> 
    <?php echo $form->dropDownList($model,'visit_type',$records,array('empty' => 'Select Visit Type')); ?> 
    <?php echo $form->error($model,'visit_type'); ?> 
</div> 
<div class="row col2"> 
     <?php echo $form->labelEx($model,'next_visited_date'); ?> 
     <?php 
     $this->widget('zii.widgets.jui.CJuiDatePicker',array(
      'model' => $model, 
      'attribute'=>'next_visited_date', 

      //'flat'=>true,//remove to hide the datepicker 
      'options'=>array(
       'showAnim'=>'drop',//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop' 
       'dateFormat' => 'yy-mm-dd', 
       'showButtonPanel' => true,  // show button panel 
      ), 
      'htmlOptions'=>array(
       'style'=>'' 
      ), 
     )); 
     ?> 
    <?php echo $form->error($model,'next_visited_date'); ?> 
    </div> 

我不得不改變根據出訪選擇的類型的訪問日期。

+0

顯示一些代碼。 – Criesto

回答

0

你將不得不使用ajax此:

更改您的下拉使用ajax,像:

<?php echo $form->dropDownList($model,'visit_type',$records,array(
             'empty' => 'Select Visit Type', 
             'ajax' => array(
             'type'=>'POST', 
             'url'=>CController::createUrl('controller/myAction'),//your controller and action name 
             'update'=>'#Model_next_visited_date', //replace Model with the model name 
             'success'=> 'function(data) { 
             $("#Model_next_visited_date").empty(); //replace Model with the model name 
             $("#Model_next_visited_date").val(data); //replace Model with the model name 
             } ' 
            ))); 
    ?> 

,並創建一個新的動作:

public function actionMyAction() 
    { 
     //you will receive drop down value in $_POST['Model']['visit_type'] 
     // Place your date logic here..... 
    } 

希望這有助於

+0

是的,它幫助了我,謝謝。 –