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"
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0.3 or above
- JQuery
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
See 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."]";
}
Change Log ¶
May 22, 2009 ¶
- Initial release.
Cool but...
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 !
isn't it json?
why build the json by hand instead of json-encode?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.