Pass a variable into JuiDialog

Hi!

I use CGridView widget for listing some data. At the last column the three buttons are listed.


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'gallery-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'name',

		array(

			'class'=>'CButtonColumn',

			'template' => '{update}{delete}{add}',

			'buttons' => array(

				'add'=>array(

					'url'=>'Yii::app()->createUrl("/gallery/add", array("id" => $data->id))',

					'imageUrl'=>Yii::app()->createUrl("/images/add.png"),

					'click'=>'js:function() { $("#gallery-add").dialog("open"); $("#gallery-add-form-field-parent").val("' . $data->id . '"); return false; }',

				),

			),

		),

	),

)); ?>

As you can see at the Add button I call the open dialog for displaying the JuiDialog. In that dialog I have a form for ajax request:


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'gallery-add-form',

	'enableAjaxValidation'=>true,

)); ?>

	

	<?php echo $form->hiddenField($model,'parent', array('id'=>'gallery-add-form-field-parent')); ?>

	

	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name', array('autocomplete'=>'off')); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>

	

	<?php echo CHtml::ajaxButton(

		'Save', 

		Yii::app()->createUrl('ajax/index'), 

		array(

			'type'=>'post',

			'dataType'=>'json',

			'beforeSend'=>'function() { 

				$("#resp").html("<img src=\"' . Yii::app()->createUrl('/images/loading.gif') . '\" />"); 

			}',

			'success'=>'function(resp){

	                    alert('ok');

	                }',

		), 

		array(

			'type'=>'submit'

		)

  	); ?>

  	

  	<div id="resp"></div>


<?php $this->endWidget(); ?>

I need to pass into this form the Parent parameter for ajax sending. So I dont know how to pass $data->id into JuiDialog. $data->id works only in ‘url’ key of the buttons array, and in ‘click’ key it returns empty string.

I found one possible idea. I catch the id from the generated url:




'add'=>array(

	'url'=>'Yii::app()->createUrl("/gallery/add", array("id" => $data->id))',

	'imageUrl'=>Yii::app()->createUrl("/images/add.png"),

	'click'=>'js:function() { 

		$("#gallery-add").dialog("open"); 

		

		var rx = /=(\d+)$/;

		var arr = rx.exec($(this).attr("href"));

		

		$("#gallery-add-form-field-parent").val(arr[1]);

		

		return false; 

	}',

),



[font="Trebuchet MS"]great tricky man… i love it… this is solve my problem. is there another way to do this without tricky?

anyway thanks with this idea… very helping me.[/font]

I don’t know regular expression. Is there a normal way to solve this problem?