Yii Framework Forum: Multiselect Dependent Dropdown - Yii Framework Forum

Jump to content

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

Multiselect Dependent Dropdown Rate Topic: -----

#1 User is offline   uwaisfariz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 23-April 13

Posted 03 July 2014 - 11:09 AM

Hi,

I implemented the dependent dropdown properly. But when I tried to change the dropdownlist to multi-select dropdown, I am unable to pass all the selected values to the controller via ajax data. By below method, I am able to pass one value. But how do I pass more than one value ?


 echo $form->dropDownList($model, 'cityList',
    CHtml :: listData(City:: model()->findAllByAttributes(array('in_group'=>'city')), 'id', 'name'),
        array(
	   'multiple'=>'multiple',
	    'ajax' => array(
            'type' => 'POST',
            'url' => Yii::app()->createUrl('site/getstreet') ,		
	   'data'=> array('cityy' => 'js:this.value' ),         
           'update'=>'#street',
            'success' => 'function(data){	
				
				//myfunction
                
            }',					
            ),
            
        ));



0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,079
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 03 July 2014 - 02:46 PM

it will send the id's of selected options as string to the server

NOTE: its likely gonna do more than one ajax i have not tested it

<?php echo $form->dropDownList($model, 'cityList', City:: model()->findAllByAttributes(array('in_group'=>'city')), 'id', 'name'), [
	'multiple'=>'multiple',
	'ajax' => array(
		'type' => 'POST',
		'url' => Yii::app()->createUrl('site/index'),
		'data'=>['city'=>'js:this.value'],
		'update'=>'#street',
		'beforeSend'=>'js:function(xhr){this.data=encodeURI( "city=" + $("#cityList").val().join(",") );}',
		'success'=>'js:function(data) {console.log(data);}'
	),
]); ?>

0

#3 User is offline   uwaisfariz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 23-April 13

Posted 04 July 2014 - 03:09 AM

View Postalirz23, on 03 July 2014 - 02:46 PM, said:

it will send the id's of selected options as string to the server

NOTE: its likely gonna do more than one ajax i have not tested it

<?php echo $form->dropDownList($model, 'cityList', City:: model()->findAllByAttributes(array('in_group'=>'city')), 'id', 'name'), [
	'multiple'=>'multiple',
	'ajax' => array(
		'type' => 'POST',
		'url' => Yii::app()->createUrl('site/index'),
		'data'=>['city'=>'js:this.value'],
		'update'=>'#street',
		'beforeSend'=>'js:function(xhr){this.data=encodeURI( "city=" + $("#cityList").val().join(",") );}',
		'success'=>'js:function(data) {console.log(data);}'
	),
]); ?>



Thanks for your reply. I found a simple way. I got all the values selected directly inside the controller using $_POST.
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