Yii Framework Forum: Dropdownlist Select From Parent - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dropdownlist Select From Parent Rate Topic: -----

#1 User is offline   freshyiiuser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 07-March 13

Posted 17 May 2013 - 01:18 PM

i have 3 levels of dropdownlist

i have to select first the behavior type [negative, positive)
based on the type, i have to select the behavior group and finally the behavior

i am beginner in yii and ajax, i got an example from the internet and i tried to apply it to yii

the example didn't work in yii, but it's workable in pure php

can anyone tell me where is the error.

thanks in advance
Attached File  _formcreate.php (2.96K)
Number of downloads: 4Attached File  dd.php (581bytes)
Number of downloads: 3Attached File  dd2.php (293bytes)
Number of downloads: 2
0

#2 User is offline   freshyiiuser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 07-March 13

Posted 17 May 2013 - 03:46 PM

i tried also based on this website

_form is
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'assignment-form',
	'enableAjaxValidation'=>false,
	'enableClientValidation'=>true,
)); 

?>

<?php echo $form->dropDownList($model,'BehavType', array(Yii::app()->params['bType']),array('empty'=>'Select Type'),
array(
'ajax' => array(
'type'=>'GET', //request type
'url'=>$this->createUrl('Assignment/getBehaviorGroup'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'data'=>array('BehavType'=>'js:this.value'),
//'data'=>array('BehavType'=>'js:this.value'), 
//leave out the data key to pass all form values through
))); 
 
//empty since it will be filled by the other dropdown
echo $form->dropDownList($model,'behavGroupID', array()); ?>

	


in Assignment controller
		public function actionGetBehaviorGroup()
	{
		$data=Category::model()->GetCatOfType($_POST['BehavType']);//findAll('parent_id=:parent_id', array(':parent_id'=>(int) $_POST['BehavType']));
	
		$data=CHtml::listData($data,'color','color');
		foreach($data as $value=>$name)
		{
			echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
		}
		
		//echo $_POST['BehavType'];
	}


public function accessRules()
	{
		return array(
		
			array('allow',
				'actions'=>array('index','create','admin','view','update','assign', 'getBehaviorGroup'),
				'roles'=>array('admin','BASAdmin','Assistant','Teacher'),
				'users'=>array('@'),
			),
}




there is no result, it seems that the first dropdownlist doesn;t even go to the controller. is there any errors in this code?
0

#3 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 329
  • Joined: 10-November 10

Posted 18 May 2013 - 06:06 AM

Have you checked your ajax response (via Firebug)? Does it show some errors?
Fipick - Find and pick recommendations
0

#4 User is offline   freshyiiuser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 07-March 13

Posted 23 May 2013 - 03:47 AM

View Postrei, on 18 May 2013 - 06:06 AM, said:

Have you checked your ajax response (via Firebug)? Does it show some errors?

yes, there is no error.
i putted an alert at the beginning of the ajaxfunction to see if the ajax code is executed. there is no result. it seems that the ajax code is not visible.
0

#5 User is offline   freshyiiuser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 07-March 13

Posted 29 May 2013 - 09:45 AM

the code is works now fine for me. but i need to use $form->dropdownlist in the second dropdownlist instead of CHtml::dropdownlist in order to save the selected value in the database. and i use $form->dropdownlist, the second list is empty even the result appeared in the firebug but not displayed in the html view.

how to solve this issue?
this is the code
in view
<div class="row">
		<?php
			//  select the Behavior Type
			echo $form->dropDownList($model,'BehavType', array(Yii::app()->params['bType']),
					array(
					'ajax' => array(
						'type'=>'POST', //request type
						'url'=>CController::createUrl('Assignment/getBehaviorGroup'), //url to call.
						'update'=>'#behavGroupID',
					))); 
		?>
	</div>
	<div class="row">
		<?php
			//  select the Behavior Group 
			echo $form->dropDownList($model,'behavGroupID',  array(),
					array(
					'ajax' => array(
						'type'=>'POST', 
						'url'=>CController::createUrl('Assignment/getBehavior'), //url to call.
						'update'=>'#behavID',
					))); 
									
			echo $form->error($model,'behavGroupID');
			echo "&nbsp &nbsp";
			
			//  select the Behavior
			echo $form->dropDownList($model,'behavID',array());
			echo $form->error($model,'behavID');
		?>
	</div>


in the controller
	public function actionGetBehaviorGroup()
	{
		$assignment = Assignment::model()->GetAssignmentInfo($_POST['Assignment']['BehavType']);
		
		$data=CHtml::listData($assignment,'ID','E_BGName');
		
		foreach($data as $value=>$name)
		{
			echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
		}
	}
	
	public function actionGetBehavior()
	{
		$behavior = Behavior::model()->findAll('behavGroupID=\'' . $_POST['Assignment']['behavGroupID'] . '\'');
		$data=CHtml::listData($behavior,'ID','E_Name');
		
		foreach($data as $value=>$name)
		{
			echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
		}
	}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users