Yii 1.1: jquerycascadeselect

JQuery Cascade Select
5 followers

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.

Total 2 comments

#2347 report it
Leric at 2010/12/15 10:08pm
isn't it json?

why build the json by hand instead of json-encode?

#1493 report it
ChrOnOs at 2009/07/15 10:33am
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 !

Leave a comment

Please to leave your comment.

Create extension