I have 3 dropdownlists in a form. When the first one gets selected it should update the other two using two separate ajax calls, one for each dropdownlist.
My current code is
<?php echo $form->dropDownList($model,'semestre_id',
CHtml::listData(semestres::todos(), 'id', 'semletivo'),
array('prompt' => 'Escolha o semestre',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl ('inscricoes/dynamicDisciplinas/cursoid/'.$cursoid.'/alunoid/'.$alunoid), //url to call.
'update'=>'#'.CHtml::activeId($model,'disciplina'),
),
));
?>
It works fine but it only updates one dropdownlist.
How do I make two ajax calls in order to update two objects when the first dropdownlist gets selected?
done that. it doesn’t work. updating list2 does not trigger load on list 3.
I need to write a function that makes two ajax calls to 2 different actions on the controller and that will update both list 2 and 3. just don’t know how… I’ve done intensive searching but all examples I find only update one list, not two.
I have done 3 cascaded off of a main dropdown, but each only triggers once you fill in the next one. Not sure if this is the same thing you are looking to do. For example -
Main dropdown was the MAKE, then once selected MODEL gets filled, once MODEL is selected (changed) then TRIM gets filled. So the issue is that if they are dependent then how could the list fill based on a previous list if their is no change in that list? Does that make sense? Each Ajax call is made by an internal trigger to the onchange event and if you don’t change any of the subsequent related combo boxes that even doesn’t fire so no ajax call to populate.
The other option is to do the ajax call in javascript on the main dropdown’s onchange() event. It’s not hard but a bit tricky to make it work at first, then not too bad.
One last think is to use Firebug and watch the calls, I ran into a problem where things were set up correctly but I had made an error in one of the actions in the controller and the result was a 500 error. Watching that in Firebug was most helpful in catching those type of problems. For ever dropdown that you change you should see a server call with a 200 result code or something is likely wrong.
Possibly in the controller ajax call you could return two variables in the returned data that are json encoded representations of the dataLists. Something like: