Update A Model In A Modal Cjuidialog

Hello people!

I have a "Order" form where I can select a person and then proceed filling the data. If the person not exist, I can Add It by a button beside the drop down of person select (CJuiDialog). This part is working ok.

But I want to create another button (Update) to allow the user to edit a selected ‘person’ in a CJuiDialog (like Adding), but I can’t obtain the selected person ID from the dropdownlist.

Here is my code. Can someone help me?




<script type="text/javascript">

function updatePessoa()

{	

    <?php echo CHtml::ajax(array(

            'url'=>array('pessoa/update&id= <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?'),  <========  Here I want to get a dropdownlist selected value (id) for editing...

            'data'=> "js:$(this).serialize()",

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#dialogPessoa div.divForForm').html(data.div);

                          // Here is the trick: on submit-> once again this function!

                    $('#dialogPessoa div.divForForm form').submit(updatePessoa);

                }

                else

                {    		

                    $('#dialogPessoa div.divForForm').html(data.div);    	    				    	

    				//window.parent.$('#Reclamacao_pessoa_reclamante_id').prepend('<option value=\"' + data.pessoa_id +'\" selected=\"selected\">' + data.pessoa_nome + '</option>');

                    setTimeout(\"$('#dialogPessoa').dialog('close') \",3000);    	

                }

 

            } ",

            ))?>;

    return false; 

}

</script>



And here is my CJuiDialog, my dropDownList (with name ‘pessoa_reclamante_id’) where I want to get the selected value and the button that opens the dialog.





<?php 

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

    'id'=>'dialogPessoa',

    'options'=>array(

        'title'=>'Update Pessoa',

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>550,

        'height'=>470,

    ),

));?>


<div class="row">

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

		<?php echo $form->dropDownList($model, 'pessoa_reclamante_id', GxHtml::listDataEx(Pessoa::model()->findAllAttributes(null, true)));?>

		</div><!-- row -->

		<div class="row">

		<?php $dialog_button = '<button type="button" class="btn btn-primary" data-loading-text="Loading...">Novo</button>';

		echo CHtml::link($dialog_button, '#', array(

  						 'onclick'=>"{updatePessoa(); $('#dialogPessoa').dialog('open'); return false;}"	

		));?>



Solved It using jQuery directly.




function updatePessoa()

{

    //http://www.yiiframework.com/forum/index.php/topic/20273-passing-parameters-to-an-ajax-link/

    jQuery.ajax({

        'url': 'index.php?r=pessoa/update&id=' + document.getElementById('Reclamacao_pessoa_reclamante_id').value,

        'data': $(this).serialize(),

        'type':'post',

        'dataType':'json',

        'success':function(data)

        {

            if (data.status == 'failure')

            {

                $('#dialogPessoa div.divForForm').html(data.div);

                // Here is the trick: on submit-> once again this function!

                $('#dialogPessoa div.divForForm form').submit(updatePessoa);

            }

            else

            {

                $('#dialogPessoa div.divForForm').html(data.div);

                window.parent.$('#Reclamacao_pessoa_reclamante_id option:selected').remove();

                window.parent.$('#Reclamacao_pessoa_reclamante_id').prepend('<option value=\"' + data.pessoa_id +'\" selected=\"selected\">' + data.pessoa_nome + '</option>');

                setTimeout("$('#dialogPessoa').dialog('close')" ,3000);

            }


        }

    });

    return false;

}