Yii Framework Forum: Dependent Bootstrap Dropdownlist Ajax Problem - Yii Framework Forum

Jump to content

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

Dependent Bootstrap Dropdownlist Ajax Problem 2 dropdownlist, dropdownlist[A] is dependent to drowdownlist[B] Rate Topic: -----

#1 User is offline   nhexia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 15-November 12

Posted 17 January 2013 - 11:08 PM

my form

<style type="text/css">
      .alert{ width: 500px;}
      #hide{ visibility: hidden;}
</style>
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'cash-advance-form',
	'enableAjaxValidation'=>false,
)); ?>
        <?php 
            $this->widget('bootstrap.widgets.TbLabel', array(
                   'type'=>'info', // 'success', 'warning', 'important', 'info' or 'inverse'
                   'label'=>'Fields with * are required',
                   'htmlOptions'=>array('style'=>'padding:5px;')
               ));
        ?>
        <br/><br/>
        <?php $user = Yii::app()->user->name ;?>
	<?php echo $form->errorSummary($model); ?>
        
        <?php
        echo ($model->isNewRecord ? 
                $form->textFieldRow($model,'id',array('class'=>'span5','maxlength'=>32,'value'=> OpexCashAdvance::model()->getCAID(),'readonly'=>'readonly',))
                :
                $form->textFieldRow($model,'id',array('class'=>'span5','maxlength'=>32,'readonly'=>'readonly',))
                );
        ?>      
	<?php echo $form->textFieldRow($model,'amount',array('class'=>'span2','style'=>'text-align:right;font-size:16px','maxlength'=>12,'append'=>'.00','value'=>'0')); ?>
        <?php echo $form->labelEx($model,'department'); ?>
        <?php 
                echo $form->dropDownList($model,'department',
                CHtml::listData(OpexDepartment::model()->findAll(),'department_id','department_name'),
                    array('class'=>'span5','maxlength'=>12,),
                    array('ajax'=>
                            array(
                                        'type'=>'POST', //request type
                                        'url'=>CController::createUrl('OpexCashAdvance/loadcategory'), //url to call.
                                        //Style: CController::createUrl('currentController/methodToCall')
                                        'update'=>'#OpexCashAdvance_category', //selector to update
                                        //'data'=>'js:javascript statement' 
                                        //leave out the data key to pass all form values through
                                  )
                        )
             ); 
 
//empty since it will be filled by the other dropdown
#echo CHtml::dropDownList('city_id','', array());
            ?>
	<?php echo $form->labelEx($model,'category'); ?>
        <?php echo $form->dropDownList($model,'category', /*CHtml::listData(OpexCategory::model()->findAll(array('condition'=>'department_id="'.$model->department.'"')),'category_id','category_name'),*/array(/*'empty'=>'-Select-','class'=>'span5','maxlength'=>12*/)); ?>

	<?php echo $form->labelEx($model,'userid'); ?>
        <?php echo $form->dropDownList($model,'userid',CHtml::listData(Users::model()->findAll(),'userid','userRealName'), array('empty'=>'-Select-','class'=>'span5','maxlength'=>12)); ?>
        
        <?php echo $form->labelEx($model,'branch'); ?>
        <?php echo $form->dropDownList($model,'branch', CHtml::listData(Branches::model()->findAll(/*array('condition'=>'department_id="'.$model->department.'"')*/),'branch_id','branch_name'),array('empty'=>'-Select-','class'=>'span5','maxlength'=>32)); ?>
        <?php #echo $form->textFieldRow($model,'date_created',array('class'=>'span5','maxlength'=>12,'value'=>date('Y-m-d'),'readonly'=>'readonly')); ?>
        <?php 
        
        echo $form->labelEx($model,'date_created'); 
        $this->widget('zii.widgets.jui.CJuiDatePicker', array('model'=>$model,'attribute'=>'date_created','value'=>$model->date_created,'htmlOptions'=>array('maxlength'=>'11','class'=>'span-5'),'options'=>array(
                                                                                               'showAnim'=>'fadeIn',
                                                                                               'showButtonPanel'=>true,
                                                                                               'dateFormat'=>'yy-mm-dd',
                                                                                            
                                                                                               ),
                                                       )); 
        ?>
	<?php echo $form->textFieldRow($model,'desc',array('class'=>'span6','maxlength'=>100,'style'=>'resize:none;')); ?>

        <?php echo $form->textFieldRow($model,'porpose',array('class'=>'span6','maxlength'=>60,'style'=>'resize:none;')); ?>
        
        
        <div style="width: 380px; text-align: right">
                <?php $this->widget('bootstrap.widgets.TbButton', array(
                        'buttonType'=>'reset',
                        'type'=>'info',
                        'label'=>'Clear',
                )); ?>
                <?php $this->widget('bootstrap.widgets.TbButton', array(
                        'buttonType'=>'submit',
                        'type'=>'primary',
                        'label'=>$model->isNewRecord ? 'Create' : 'Save',
                )); ?>
        </div>
      
<?php $this->endWidget(); ?>



my controller function

 public function actionLoadcategory(){
            
                $data = OpexCategory::model()->findAll(
                            array('condition'=>"department_id='".$_POST['department']."'")
                        );
                echo "asdasdasdasdasdasd";
                $data=CHtml::listData($data,'category_id','category_name');
                foreach($data as $value=>$name)
                {
                    echo CHtml::tag('option',
                               array('value'=>$value),CHtml::encode($name),true);
                }
        }



i dont know why my ajax is not updating dropdownlist category any one can hep me plese, or to help me find the bug thanks in advance.
Reinhard navarro [Nhexia]
0

#2 User is offline   Reza m 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 07-March 12

Posted 18 January 2013 - 04:55 AM

debug it with firebug and see wat error you get


also use '#'.CHtml::activeId($model,'category') in ajax update attribute instead '#OpexCashAdvance_category'


  'update'=>'#'.CHtml::activeId($model,'category'),


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