Yii Framework Forum: Activedropdownlist Not Load Ajax Function When Adding Prompt - Yii Framework Forum

Jump to content

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

Activedropdownlist Not Load Ajax Function When Adding Prompt Rate Topic: -----

#1 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 231
  • Joined: 04-October 12

Posted 05 December 2012 - 09:29 AM

I had problem in yii , I created code to call ajax in activedropDownList to load values in dropDownList and every thing is work !

But my problems are :

1- when added array('prompt'=>'Select Yous country ') So code will be like that:

echo CHtml::activedropDownList($model,'country',$model->getcountry(),array('prompt'=>'Select Yous country '),

and result : not work .

But if when I removed array('prompt'=>'Select Yous country '), it's work and ajax load new list !

this is my code

View :

<?php
/* @var $this UsersController */
/* @var $model Users */
/* @var $form CActiveForm */
?>

<div class="form">

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





	

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'الأسم الأول'); ?>
		<?php echo $form->textField($model,'first_name'); ?>
		<?php echo $form->error($model,'الأسم الاول'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'العائلة'); ?>
		<?php echo $form->textField($model,'last_name'); ?>
		<?php echo $form->error($model,'العائلة'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'كلمة المرور'); ?>
		<?php echo $form->passwordField($model,'password'); ?>
		<?php echo $form->error($model,'password'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'تأكيد كلمة المرور'); ?>
		<?php echo $form->passwordField($model,'passwordconfirm'); ?>
		<?php echo $form->error($model,'passwordconfirm'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'البريد الإلكتروني '); ?>
		<?php echo $form->textField($model,'email'); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>
		<div class="row">
		<?php echo $form->labelEx($model,'تأكيد البريد الإلكتروني'); ?>
		<?php echo $form->textField($model,'emailconfirm'); ?>
		<?php echo $form->error($model,'emailconfirm'); ?>
	</div>

		<div class="row">
		<?php echo $form->labelEx($model,'تاريخ الميلاد'); ?>
	<?php

$this->widget(
	'ext.jui.EJuiDateTimePicker',
	array(
    	'model' 	=> $model,
    	'attribute' => 'birth_date',
    	'language'=> 'en',//default Yii::app()->language
     	'mode'	=> 'date',//'datetime' or 'time' ('datetime' default)
    	'options'   => array(
    	'dateFormat' => 'yy-mm-dd',
        	//'timeFormat' => '',//'hh:mm tt' default
    	),
	)
);


?>

		<?php echo $form->error($model,'birth_date'); ?>
	</div>





	<div class="row">
		<?php echo $form->labelEx($model,'الجنس'); ?>
		<?php echo chtml::activeDropDownList($model,'gender',$model->getStatusOption(),array('prompt'=>'أختر جنسك')
); ?>
		<?php echo $form->error($model,'gender'); ?>
	</div>

		<div class="row">
		<?php echo $form->labelEx($model,'البلد'); ?>
	<?php
	
	/*
 	echo chtml::activeDropDownList($model,'country',$model->getcountry(),array('prompt'=>'اختر بلدك ')   , 
	array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('current/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))
	
	); 
	
	*/
	echo CHtml::activedropDownList($model,'country',$model->getcountry(),array('prompt'=>'اختر البلد أو المنطقة '),
	
	array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('register/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))
	);
   
   
   ///
   
   

	
	////
	
	?>
 
	
		<?php echo $form->error($model,'country'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'المدينة'); ?>
		<?php 
   	//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city','', array());

//echo CHtml::activedropDownList($model,'city',array());
 ?>
		<?php echo $form->error($model,'city'); ?>
	</div>



	<div class="row">
		<?php echo $form->labelEx($model,'رمز الاتصال'); ?>
		<?php echo $form->textField($model,'mobile_code'); ?>
		<?php echo $form->error($model,'mobile_code'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'رقم الجوال'); ?>
		<?php echo $form->textField($model,'mobile_number'); ?>
		<?php echo $form->error($model,'mobile_number'); ?>
	</div>




	<div class="row buttons">
		<?php echo CHtml::submitButton('تسجيــــــــــــل'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->





Ajax Controller :



public function actionDynamiccities() /// Called Ajax
{
$country=intval($_POST['Users']['country']);
  
   	$data=Cities::model()->findAll('country_id=:country_id', 
              	array(':country_id'=>$country));
 $data=CHtml::listData($data,'id','city_name_e');
	
	foreach($data as $value=>$name)
	{
    	echo CHtml::tag('option',
               	array('value'=>$value),CHtml::encode($name),true);
	};


}  
   


	


thanks in advance


0

#2 User is offline   alirz23 

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

Posted 05 December 2012 - 11:26 AM

This is trick but it will sort your problem.


public function actionDynamiccities() /// Called Ajax
{
$country=intval($_POST['Users']['country']);
  
        $data=Cities::model()->findAll('country_id=:country_id', 
                array(':country_id'=>$country));
 $data=CHtml::listData($data,'id','city_name_e');
        echo CHtml::tag('option',
                array('value'=>''),CHtml::encode('Select Your Country'),true);
        foreach($data as $value=>$name)
        {
        echo CHtml::tag('option',
                array('value'=>$value),CHtml::encode($name),true);
        };


}  

1

#3 User is offline   samilo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 231
  • Joined: 04-October 12

Posted 06 December 2012 - 01:22 AM

Thank you alirz23

also I found this solution :
array(   'prompt'=>'اختر البلد أو المنطقة ',   'ajax' => array(     'type'=>'POST', //request type     'url'=>CController::createUrl('register/dynamiccities'), //url to call. //Style: CController::createUrl('currentController/methodToCall')     'update'=>'#city', //selector to update     //'data'=>'js:javascript statement'      //leave out the data key to pass all form values through   ) )



http://stackoverflow...727797#13727797

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