2014-11-05 51 views
3
<?php 
    echo $form->dropDownList($model,'ment_id', $mentslists, 
     array(
     'prompt'=>'Select ment', 
     'class'=>'required' 
    )); 
    echo $form->error($model,'ment_id'); 
    ?> 

Onchange dropdownlist我想爲CMultiFileUpload設置最大值。Onchange下拉列表動態設置最大值yii CMultiFileUpload

我CMultiFileUpload代碼,

 <?php 
$this->widget('CMultiFileUpload', array(
      'name' => 'data1', 
      'attribute' => 'image', 
      'accept' => 'doc|docx|pdf|txt|jpeg|jpg|png', 
      'max' => 10, 
      'duplicate' => 'file appears twice', 
      'remove' => Yii::t('ui', 'Remove'), 
     )); 
     ?> 

我試圖平變化從下拉列表數據庫,如何將值應用到最大領域獲得最大的允許大小值。

我jQuery代碼是,

$("#ment_id").on('change',function() 
     { 
    $.ajax({ 
    type: "POST", 
    url: "/ments/default/GetmentDetails", 
    data: {'ment_id':$(this).val()}, 
    success: function(data){ 
     //data having the max upload value    
     } 
    }); 
     }); 

我的控制器代碼,

public function actionGetmentDetails() 
    { 
     $id = $_POST['ment_id']; 
     $assign_details = Ments::model()->findAllByAttributes(array('id'=>$id)); 
     echo $assign_details[0]['c_max_upload_files']; 
     exit; 
    } 

如何設置動態地根據不斷變化的下拉列表中最大值,

+0

你有一個網站,這是運行在看看? – Demodave 2014-11-06 18:40:46

回答

0

這是一個有點模糊,你卡在哪個點上,這裏是在javacript/jquery中的後退和前進。

$("#ment_id").on('change',function(){ 

    // Get max value before the ajax call 
    var maxValue = undefined; 
    $('option', $(this)).each(function() { 
     var val = $(this).attr('value'); 
     val = parseInt(val, 10); 
     if (maxValue === undefined || maxValue < val) { 
      maxValue = val; 
     } 
    }); 

$.ajax({ 
    type: "POST", 
    url: "/ments/default/GetmentDetails", 
    data: {'ment_id':$(this).val()}, 
    success: function(data){ 
     //setting the retrieved max value by ajax response value 
     $("#ment_id").val(data.max_value); 
     } 
    }); 
}); 

如果你想在PHP貼出的價值並獲得傳遞給小部件的代碼,它更是一個地方是小部件方法被稱爲問題的,因爲你的價值已經是$ _ POST到位。