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.
Need some changes to your controller method
Since you are providing an example for everyone to implement, I would recommend:
In actionList(), wrap the output with:
if(Yii::app()->request->isAjaxRequest)
{
}
else
{
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
Additionally, please end the output of actionList() properly, using
Yii::app()->end();
so that debugging output doesn't screw with the json output.
bug on windows server
Never use DIRECTORY_SEPARATOR in URL!
$js = $this->baseUrl . '/jquery.cascade-select.js';
enable filter
Hey, I like your extension! But I don't get to run the filter stuff:(
Here is my code:
<?php $qvfields = $this->createWidget('ext.JQueryCascade.jQueryCascade'); echo $qvfields->dropdownList('Qvfilters[qvf_id]', $_GET['id'], CHtml::listData(Qvfields::model()->findAll("qvf_docName = :qvf_docName",array(':qvf_docName'=>strtoupper(Reports::model()->findByPK($_GET['id'])->ber_docName))),'qvf_id','qvf_fieldName'), array( 'ajax'=>array( 'type'=>'POST', 'url'=>Yii::app()->createUrl('//qvmapping/loadvalues'), 'update'=>'#qvv_values', 'data'=>array('id'=>'js:this.value'), ), 'searchable'=>'true', ), CController::createUrl('qvfields/listFields'), 'tt_qvf_id', '' ); ?>
And then in the controller:
public function actionListFields() { if (Yii::app()->request->isAjaxRequest) { $docName = strtoupper(Reports::model()->findByPK($_GET['selected'])->ber_docName); $Fields = Qvfields::model()->findAll('qvf_docName = :qvf_docName',array(':qvf_docName'=>$docName)); $Labels = array(); foreach ($Fields as $Field) { $Labels[] = array('label' => $Field->qvf_fieldName, 'value' => $Field->qvf_id,'searchable'=>'true'); } echo json_encode($Labels); Yii::app()->end(); } else { throw new CHttpException(400, 'Invalid request.'); } }
And one other issue is, that I try to set the selection by javascript Jquery - but I don't get it to run:(
Thank you for your help!
Cheers Phil
reply: enable filter
@philippfrenzel,
Filter is now working
Hi,
I got the filter working;) Sorry, my fault...
<?php $qvfields = $this->createWidget('ext.JQueryCascade.jQueryCascade'); echo $qvfields->dropdownList('Qvfilters[qvf_id]', $_GET['id'], CHtml::listData(Qvfields::model()->findAll("qvf_docName = :qvf_docName",array(':qvf_docName'=>strtoupper(Reports::model()->findByPK($_GET['id'])->ber_docName))),'qvf_id','qvf_fieldName'), array( 'ajax'=>array( 'type'=>'POST', 'url'=>Yii::app()->createUrl('//qvmapping/loadvalues'), 'update'=>'#qvv_values', 'data'=>array('id'=>'js:this.value'), ), 'filter'=>'true', ), CController::createUrl('qvfields/listFields'), 'tt_qvf_id', '' ); ?>
But I still have the problem, that I'm not able to set the value...:( How can I do that...
I tried with:
$('#Qvfilters_qvf_id').multiselect().selectText(data.qvf_id);
Cheers Phil
Select Value from javascript
Here we go:
Anyway the header doesn't change:(
function updateEditFormFilters(target_id){ $('#Notification').jnotifyAddMessage({ text: 'Loading filters...', permanent: false, showIcon: true }); var id =$.fn.yiiGridView.getSelection(target_id); $('#fil_save_button').attr('value', (id > 0 ? 'update' : 'create')); $.getJSON('<?php echo Yii::app()->createUrl("//qvfilters/subviewload"); ?>'+'&id='+id, function(data) { $('#Qvfilters_filter').val(data.filter); $('#Qvfilters_fil_id').val(data.fil_id); $('#Qvfilters_qvf_id').val(data.qvf_id); $('#Qvfilters_qvf_id').multiselect('widget').find('input[value="'+ data.qvf_id +'"]').trigger('click'); $('#Qvfilters_rec_id').val(data.rec_id); }); return false; }
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.