Onchange dropdown sets max value dynamically yii CMultiFileUpload
<?php
echo $form->dropDownList($model,'ment_id', $mentslists,
array(
'prompt'=>'Select ment',
'class'=>'required'
));
echo $form->error($model,'ment_id');
?>
Onchange dropdownlist I want to set maximum value for CMultiFileUpload.
my code is 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'),
));
?>
I tried onchange dropdown to get max allowed size value from database how to apply value to max .
my jquery code is there,
$("#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
}
});
});
my controller code,
public function actionGetmentDetails()
{
$id = $_POST['ment_id'];
$assign_details = Ments::model()->findAllByAttributes(array('id'=>$id));
echo $assign_details[0]['c_max_upload_files'];
exit;
}
how to set max value dynamically based on change of dropdown,
+3
source to share
1 answer
A bit vague at what point you get stuck, here is the back and forth in 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);
}
});
});
If you want this posted value in php and be passed to this widget code, it is more of a question to call this widget method as you already have the $ _POST value.
0
source to share