Yii Framework Forum: Dependent Dropdownbox - Yii Framework Forum

Jump to content

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

Dependent Dropdownbox Rate Topic: -----

#1 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 26 June 2014 - 12:49 AM

Hello friends..

Am using Dependent dropdownlist in my form. the thing is 1.department 2.designation.
If we select the department field the designation want to be changed. Am using some code but i got error.

Plz take a look at my code and help me out without error..

in my _form.php department dropdownlist
<?php  echo $form->dropDownList($model,'department',CHtml::listData(Department::model()->findAll(),'id','department'), array(
                    'prompt'=>'Select department',
                    'ajax' => array(
                        'type'=>'POST',
					    'url'=>CController::createUrl('User/designation'), 
						'update'=>'#User_designation',
                        'dataType'=>'json',
                        'data'=>array('id'=>'js:this.value'),  
                        'success'=>'function(data) {
						alert("hi");
						//$("#User_designation").html(data.dropDownDesignation);
                         
                        }',
            ))); ?>



in my _form.php designation dropdownlist
<?php $desg = CHtml::listData( designation::model()->findAll(array('order' => 'designation')), 'desig_id', 'designation');
        echo $form->dropDownList($model, 'designation', $desg, array(
'prompt'=>'Select designation',       
	   // 'ajax' => array(
        //'type' => 'POST', //request type
        //'url' => CController::createUrl('ajax/getCities'), //url to call.                
        //'update' => '#Address_city_id', //selector to update   
        // '//data' => array('state_id' => 'js:this.value'),
	    ));?>


Usercontroller.php
 public function actiondesignation()
    {
	    
          //states
           $data = Designation::model()->findAll('dept_id=:dept_id', array(':dept_id'=>(int) $_POST['department']));
			
            $data = CHtml::listData($data,'desig_id','designation');
           $dropDownDesignation= "<option value=''>Select</option>"; 
            foreach($data as $value=>$name)
                $dropDownDesignation .= CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
 
     
			
			
       echo CJSON::encode(array('dropDownDesignation'=>$dropDownDesignation));
		 
    //echo $dropDownStates;
	
	}



help me out and thanks..
0

#2 User is offline   mahdi1986 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 14-February 13

Posted 26 June 2014 - 04:36 AM

Hi,
you can use this extenstion,
CaseCade dropDown
0

#3 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 26 June 2014 - 07:45 PM

View Postvijay p s, on 26 June 2014 - 04:20 AM, said:

hello your link is for hindi song lyrics.. send me exact link.



Oh Im sorry. So stupid of me. I mean this Correct Link
0

#4 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 27 June 2014 - 06:17 AM

View Postadrianna, on 26 June 2014 - 07:45 PM, said:

Oh Im sorry. So stupid of me. I mean this Correct Link


Thanks for the link @adrinna bt I didnt get what i exactly want.. Now am create a new dropdown and am used ur link but i didnt get..
plz help me out i think the problem is in call the controller..

Am stuck with this for a week... plz help me out
0

#5 User is offline   Daniel Galvan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 04-March 12
  • Location:Mexico

Posted 27 June 2014 - 11:48 AM

View Postvijay p s, on 27 June 2014 - 06:17 AM, said:

Thanks for the link @adrinna bt I didnt get what i exactly want.. Now am create a new dropdown and am used ur link but i didnt get..
plz help me out i think the problem is in call the controller..

Am stuck with this for a week... plz help me out



I think the following post response could help you http://www.yiiframew...post__p__252641 , it is in spanish, so, if you need help, let me know.

Regards

:D
If my post was useful, Would you might give a vote +? / Si mi mensaje fue útil, ¿Le podrías dar un voto +?

Thanks / Gracias
1

#6 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 28 June 2014 - 01:16 AM

@Daniel Galvan thank u for ur response.
errorI got this error help me out

Invalid argument supplied for foreach()..


this s my code on controller i got that "Invalid argument supplied for foreach().."
public function actionDynamiccities()
 
{
  $sql = "SELECT * FROM city ".
         "WHERE state_id = :state";
  $command = Yii::app()->createCommand($sql);
  $command->bindValue(':state', $_POST['Address']['state']);
  $data = $command->execute();
  /* $data=City::model()->findAll('state_id=:state_id', 
                  array(':state_id'=>(int) $_POST ['Address']['state']));*/
 
    $data=CHtml::listData($data,'city_id','city');
 
 foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
    }
}

I got error error in this line. if i comment this line in my _view. i didnt get error and i didnt got result..
echo $form->dropDownList($model,'city','',array());

0

#7 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 29 June 2014 - 10:06 PM

View Postvijay p s, on 27 June 2014 - 06:17 AM, said:

Thanks for the link @adrinna bt I didnt get what i exactly want.. Now am create a new dropdown and am used ur link but i didnt get..
plz help me out i think the problem is in call the controller..

Am stuck with this for a week... plz help me out


Have you encountered any error? What is that error? You did'nt get what?
0

#8 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 30 June 2014 - 05:01 AM

View Postadrianna, on 29 June 2014 - 10:06 PM, said:

Have you encountered any error? What is that error? You did'nt get what?


@andrianna I didn't get any error! when I select that state, city want to be changed to exactly what state it belongs to. but city didnt change. now city is an empty dropdown.
0

#9 User is offline   Daniel Galvan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 04-March 12
  • Location:Mexico

Posted 30 June 2014 - 11:01 AM

View Postvijay p s, on 28 June 2014 - 01:16 AM, said:

@Daniel Galvan thank u for ur response.
errorI got this error help me out

Invalid argument supplied for foreach()..


this s my code on controller i got that "Invalid argument supplied for foreach().."
public function actionDynamiccities()
 
{
  $sql = "SELECT * FROM city ".
         "WHERE state_id = :state";
  $command = Yii::app()->createCommand($sql);
  $command->bindValue(':state', $_POST['Address']['state']);
  $data = $command->execute();
  /* $data=City::model()->findAll('state_id=:state_id', 
                  array(':state_id'=>(int) $_POST ['Address']['state']));*/
 
    $data=CHtml::listData($data,'city_id','city');
 
 foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
    }
}

I got error error in this line. if i comment this line in my _view. i didnt get error and i didnt got result..
echo $form->dropDownList($model,'city','',array());





Well, I think this is because of $data is empty. Are you sure $_POST has $_POST ['Address']['state']? Maybe it has another name, you can use the browser console to see exactly what parameters (POST) are you sending.

:unsure:
If my post was useful, Would you might give a vote +? / Si mi mensaje fue útil, ¿Le podrías dar un voto +?

Thanks / Gracias
1

#10 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 01 July 2014 - 12:47 AM

View Postvijay p s, on 30 June 2014 - 05:01 AM, said:

@andrianna I didn't get any error! when I select that state, city want to be changed to exactly what state it belongs to. but city didnt change. now city is an empty dropdown.


Try to replace 'id' to 'region_id' in actionDistricts on your controller from the link I give you.....and it should work.
0

#11 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 01 July 2014 - 06:15 AM

View Postadrianna, on 01 July 2014 - 12:47 AM, said:

Try to replace 'id' to 'region_id' in actionDistricts on your controller from the link I give you.....and it should work.

@adrianna and @ daniel..
Now am created the new application in yii. And am using the same code in that new one, now this dependent dropdown is working. but its not working in the current application. but i want to implement this in the current application.!!!

i don't know y, & i didn't face this type of uff! ..
0

#12 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 10-January 14
  • Location:India

Posted 03 July 2014 - 05:56 AM

Atlast I cleared my error.

The problem is in the access rule. when we add a new function in the controller we need to add the function name in the access rule and we need to specify the authenticate for user or for the admin.. that's y i got error in POST the value to the controller.

My new function in my controller is dynamicCategory().

array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete','DynamicCategory'),
'users'=>array('admin'),
),
PLZ read the article carefully line by line before u start working. @amazing , @andriana , @daniel thank you for your endless support and for the yiiteam.
0

#13 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 03 July 2014 - 07:40 AM

Yes . Use yii rights module for access control .
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
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