Hi,
I wrote a CGuiDialog based on this wiki http://www.yiiframework.com/wiki/72/cjuidialog-and-ajaxsubmitbutton/
In the dialog I have a dropdownlist which calls to ajax function on change event, and a submit function that execute javascript.
Here is the code:
<div>
<table class="cftable">
<tr>
<td>
<?php
$cf = new commonFunctions;
$text = "";
$dir = "xxx/images/" . $modelDir;
$list = $cf->buildFilesList($dir, true);
if (isset($list))
{
echo CHtml::dropdownlist('_cmchoosePicDDL','',
$list,
array('size' => 10,
'ajax' => array(
'type'=>'POST', 'url'=>CController::createUrl('ImgPreview'),
'data'=>array('bfileNum'=>'js:this.value', 'dirname' =>$dir),
'dataType'=>'json',
'success' => 'function(data) {
$("#_cmfileImage").html(data.fileImage);}',
)), array ('id' => '_cmchoosePicDDL'));
}
else
{
echo 'no files found';
}
?>
</td>
<td>
<div id="_cmfileImage"></div>
</td>
</tr>
</table>
<div class="row buttons">
<?php
echo CHtml::SubmitButton('select',
array('onclick'=>'var selectVal = $("#_cmchoosePicDDL option:selected").text();
alert(selectVal); $("#carModelPic1").val(selectVal); ’ . ‘$("#carPicDialog1").dialog(“close”);’),
array('id'=>'closePicDialog' )) ; ?>
</div>
</div>
The problem is that the "change" event is executed multiple times.
One time at the first popup one 2 at the second 3 at the third etc….
I am working with firebug and I see that when ever I popup the dialog the script is reregister under assets/xxxxx/jquery.js/eval/seq/
But it only register the call for the dropdownlist and not the submitbutton
Here is the script (from the firefox):
/<![CDATA[/
jQuery(’#carPicDialog1’).dialog({‘title’:‘choose Picture’, ,‘autoOpen’:true,‘modal’:‘true’,‘width’:‘auto’,‘height’:‘auto’});
$(‘body’).on(‘change’,’#_cmchoosePicDDL’,function(){jQuery.ajax({‘type’:‘POST’,‘url’:’/carsforumAdmin/index.php?r=cfHpMiCarsmodel/ImgPreview’,‘data’:{‘bfileNum’:this.value,‘dirname’:’/xxxx/images/x3’},‘dataType’:‘json’,‘success’:function(data) {
$("#_cmfileImage").html(data.fileImage);
},‘cache’:false});return false;});
/]]>/
This is the code for poping up the dialog.
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('PicDialog',
array('modelDir'=>$modelDir),false,true);
Any idea?
Thanks