I’ve implemented a cascade of dropdown lists that work fine in the case you arrive at the form with all lists at their default position.
However, in another use case the first list is pre-selected to a certain value to save the user time.
In this circumstance the list has to be changed, and then changed back to the value required to get the dependant list to load, which doesn’t save time! Is there someway to fire off the dependant list population when the list is loaded as well as changed?
Code from form view:
<?php echo CHtml::dropDownList('winery_id',$winid,$wineries,
array('empty' => 'Select winery',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Labels/DynamicLabels'), //url to call.
'update'=>'#label_id', //selector to update
)));
?>
Part of the answer is I’d be better with a Typeahead, but still working on that.
The first dropdown fetches vehicle makes directly and uses Ajax to fill the second dropdown which presents the vehicle models. The problem is that if the 1st loaded vehicle model has one or more trims (engine size, color, etc.) already defined they aren’t Ajax loaded into the 3rd dropdown - one has to manually change the vehicle model to something else and then go back to trigger the 3rd dropdown to update. I’m hoping that some kind of javascript “onchange” code will accomplish this.
The variable $winid is either set to -1 if no winery is pre-selected, or the winery ID if it is, so not as elegant as triggering the existing function, but works just the same.