This extension is made to build a chained select lists Tested only under the site downloaded from the forum "An idea for Role Based Access Control"
protected/extensionsSee the following code example: On top of the view:
$jqcs = $this->createWidget('application.extensions.JQueryCascadeSelect.JQueryCascadeSelect');
In the form initially you have to add a normal DropDown To add a chained DropDown you have to do one of the next lines, depinding on your needs (first params like in classic dropdown):
echo $jqcs->makeDropDown('id', '', $data, array('size'=>5),'getdata','chainedid'); echo $jqcs->makeActiveDropDown($model,'id', $data, array('size'=>5),'getdata','chainedid');
A function which serves the info needed:
public function actionGetdata() { $ret = ""; if(Yii::app()->request->isAjaxRequest) if($_GET['val'] != 'null'){ $cm = Chainedmodel::model()->findbyPk($_GET['val']); if($firm){ $neededmodels = $cm->getRelated('neededmodel'); $i = 0; foreach($neededmodels as $row){ if($i != 0) $ret .= ","; else $i++; $ret .= "{'Value':'".$row["id"]."','Text':'".$row["name"]."'}"; } } } echo "[".$ret."]"; }
Total 2 comments
why build the json by hand instead of json-encode?
In the documentation, it's better if $ret .= "{'Value':'".$row["id"]."','Text':'".$row["name"]."'}"; is replaced by $ret .= "{'Value':'".$row["id"]."','Text':'".addslashes($row["name"])."'}";
Thanks for the work !
Leave a comment
Please login to leave your comment.