Problem with activeDorpdownlist and ajax

[i]Hi, I have a problem to create a form. I have a activeDropDownList to select some values and launch an event depending of the selected value, then show or hide some form fields or elements

this is what I have [/i]

<?php echo CHtml::activeDropDownList($model,‘tipos_usuario_id’,

CHtml::listData(Tipos_Usuario::model()-&gt;findAll(),'id','tipo'),

[indent]array([/indent]

[indent][indent]‘ajax’ => array([/indent][/indent]

[indent][indent]‘type’=>‘GET’,[/indent][/indent]

[indent][indent]‘url’=>CController::createUrl(‘controller/ajaxaction’),[/indent][/indent]

[indent])[/indent]

[indent]);[/indent]

?>

y en controlador

and the controller

public function actionAjaxaction()

{

    [indent]if(Yii::app()-&gt;request-&gt;isAjaxRequest &amp;&amp; isset(&#036;_GET['tipos_usuario_id']))[/indent]





    [indent]{[/indent]

[indent]…[/indent]

[indent]}[/indent]

but I really don’t know how to go ahead. inside the controller I will put the logic that I want to return to update the form, but I don’t know how to do it

I try with the expample of cookbook but nothing, don’t work. The first problem is ajaxAction is never called.

Any idea?

I really would like to make something like the link "Click to configure post options" present in this page when start or replay a new post. Something to expand and show when the user select an option.

Just in case you missed the other cookbook article:

http://www.yiiframework.com/doc/cookbook/24/

There’s also some older threads about ajax and activedropdownlist you might find useful.

/Tommy

thanks Tommy, but I saw the article before post, and doesn’t work for me.

As I said, would like to do something like the "Click to configure post options" in this page but follow the example on cookbook I never get a good result: this is my code:

<?php echo CHtml::activeDropDownList($model,‘tipos_usuario_id’,

CHtml::listData(Tipos_Usuario::model()-&gt;findAll(),'id','tipo'),

[indent] array([/indent]

    [indent][indent]'ajax' =&gt; array(


    'type'=&gt;'POST', //request type


    'url'=&gt;'createlinks', //url to call


    //'update'=&gt;'#linktag', //selector to update


    //'data'=&gt;'js:javascript statement' 


    //leave out the data key to pass all form values through


    ))); [/indent][/indent]

?>

my controller

public function actionCreateLinks()

{   


    [indent]&#036;tipo=Tipos_Usuario::model()-&gt;find('id =:idTipo,', array(':idTipo'=&gt;(int) &#036;_POST['tipos_usuario_id']));            


    if (&#036;tipo-&gt;tipo == 'editor')


       [indent]echo 'something';[/indent][/indent]


    


}

No Ideas????

Please tell us more about what you try to accomplish. Did you include the dropdownlist in a form. What do you want to do with the value you get back from the controller.

/Tommy

Tommy in my controller I would like to show or not one or more divs. the result of the ajax operation I need to know what divs should I to show in case of the selected kind of user (editor, administrator, etc). For editor I could ask for the news topics, but for administrators I can ask for another thing. I just something like that.

This forum thread may explain a little more how to replace content based on whats selected in the dropDownList.

http://www.yiiframework.com/forum/index.php?/topic/3246-jquery-event-not-attaching-in-dynamic-renderpartial/page__hl__arobj__fromsearch__1

Since you probably do not want to include the dropDownList itself in the block being replaced you will not get into event rebinding issues.

Based on this I tested (a while ago) to select a user from the dropdown and display the complete user record. That part is easy, in your case it might need more effort based on what information you want to display.

/Tommy

Thanks Tommy, I found this too http://www.yiiframework.com/doc/cookbook/49/ I will try both.

I see. That’s the one I assumed you referred to in your first post. Now I understand your question better.

/Tommy