jquery-cascade Cascading Select Lists

  1. Documentation
  2. Change Log

Created to ease the quite repetitive task of programming cascading select lists.

Resources

Documentation

Requirements
  • Yii 1.1 or above
Installation
  • Extract the release file under protected/extensions
Usage

See the following code example:

$state = $this->createWidget('ext.jquery-cascade.jQueryCascade');

// dropDownList($id, $selected, $data, $htmlOptions = array(), $source, $cascaded)
echo $state->dropDownList('stateId',
    '',
    CHtml::listData(State::model()->findAll(), 'id', 'name'),
    '',
    CController::createUrl('city/list'),
    'cityId'
);

The function which serves the data needed:

public function actionList()
{
    if (Yii::app()->request->isAjaxRequest) {
        $state = State::model()->findByPk($_GET['selected']);
        $cities = array();

        foreach ($state->cities as $city) {
            $cities[] = array('label' => $city->name, 'value' => $city->id);
        }

        echo json_encode($cities);
        Yii::app()->end();
    } else {
        throw new CHttpException(400, 'Invalid request.');
    }
}

Change Log

Apr 20, 2011
  • Never use DIRECTORY_SEPARATOR in URLs.
    May 31, 2010
  • Initial release.
2 0
7 followers
1 552 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: mercurial
Created on: May 31, 2010
Last updated: 13 years ago

Downloads

show all