Yii Framework Forum: dependent dropdownlist not working (jQuery problem) - Yii Framework Forum

Jump to content

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

dependent dropdownlist not working (jQuery problem) Rate Topic: -----

#1 User is offline   moginn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 07-April 12
  • Location:Spain

Posted 01 November 2014 - 02:36 PM

I tried to make a dependent dropdown according to this tutorial http://www.yiiframework.com/wiki/24/ but when I place this code, the jQuery doesn't work:

	
<div class="row">
		<?php
			$htmlOptions = array('empty' => 'Please Select an option', 'ajax' =>  array("url" => $this->createUrl("user/subcategoriesByCategory"), "type" => "POST", "update" => "#Facts_sub_category"));
		?>
		<?php echo $form->labelEx($model,'main_category'); ?>
		<?php echo $form->dropDownList($model,'main_category', FactsQuestionsCategory::model()->getMainCategoryOptions(), $htmlOptions) ?>
		<?php echo $form->error($model,'main_category'); ?>
</div>


The "subcategoriesByCategory" function is never called
0

#2 User is offline   Wade Shuler 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-October 14
  • Location:Indiana

Posted 05 November 2014 - 05:15 AM

It may be dumb, but are you sure jQuery is loaded? Make sure it is loaded, and check the error console for errors.
0

#3 User is offline   moginn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 07-April 12
  • Location:Spain

Posted 05 November 2014 - 02:06 PM

View PostWade Shuler, on 05 November 2014 - 05:15 AM, said:

It may be dumb, but are you sure jQuery is loaded? Make sure it is loaded, and check the error console for errors.


yes, jQuery is loaded, because if I write the following code it works:

$(document).ready(function(){
alert('aaaa');
});

However, jQuery stops working as soon as I put the code of the dependent dropdown
0

#4 User is offline   Bizley 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 29-July 14

Posted 06 November 2014 - 01:39 AM

Are you sure "user/subcategoriesByCategory" points to the valid action? Is the request sent when you change the dropdown options? Can you show the code of "user/subcategoriesByCategory" action?
0

#5 User is offline   moginn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 07-April 12
  • Location:Spain

Posted 06 November 2014 - 03:37 PM

View PostBizley, on 06 November 2014 - 01:39 AM, said:

Are you sure "user/subcategoriesByCategory" points to the valid action? Is the request sent when you change the dropdown options? Can you show the code of "user/subcategoriesByCategory" action?


I think the request isn't sent when I change the dropdown options. This is the code:

	public function actionSubcategoriesByCategory()
	{	
		echo "<option value='1'>test1</option>";
		echo "<option value='2'>test2</option>";
		echo "<option value='3'>test3</option>";
		echo "<option value='4'>test4</option>";
	}

0

#6 User is offline   Bizley 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 29-July 14

Posted 07 November 2014 - 01:38 AM

Check if code responsible for loading the content is present. Look for any potential errors in the console (use Firebug or other similar tool).
0

#7 User is offline   Janvi Kapopara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 13-January 14

Posted 07 November 2014 - 03:57 AM

Hi,
can u show ur dependentcontroller's action code ,and ur dropdown list code..so we can exactly find out solution.
Thanks in advance.
With Regards,
Janvi
0

#8 User is offline   moginn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 07-April 12
  • Location:Spain

Posted 08 November 2014 - 12:07 AM

View PostJanvi Kapopara, on 07 November 2014 - 03:57 AM, said:

Hi,
can u show ur dependentcontroller's action code ,and ur dropdown list code..so we can exactly find out solution.


<div class="form"> 
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'facts_contribute',
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
	
	<div class="row">
		<?php
			$htmlOptions = array('empty' => 'Please Select an option', 'ajax' =>  array("url" => $this->createUrl("user/subcategoriesByCategory"), "type" => "POST", "update" => "#Facts_sub_category"));
		?>
		<?php echo $form->labelEx($model,'main_category'); ?>
		<?php echo $form->dropDownList($model,'main_category', FactsQuestionsCategory::model()->getMainCategoryOptions(), $htmlOptions) ?>
		<?php echo $form->error($model,'main_category'); ?>
    </div>
    <div class="row">
		<?php echo $form->labelEx($model,'sub_category'); ?>
		<?php echo $form->dropDownList($model,'sub_category', array(), array('empty' => 'Please Select an option')) ?>
		<?php echo $form->error($model,'sub_category'); ?>
    </div>    
    <div class="row buttons">
       <?php echo CHtml::submitButton('Ok'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div>

0

#9 User is offline   Bizley 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 29-July 14

Posted 08 November 2014 - 07:00 AM

Is your $model class called Facts?
0

#10 User is offline   moginn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 07-April 12
  • Location:Spain

Posted 08 November 2014 - 09:00 PM

View PostBizley, on 08 November 2014 - 07:00 AM, said:

Is your $model class called Facts?


yes
0

#11 User is offline   n-r 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 186
  • Joined: 19-April 13

Posted 08 November 2014 - 11:49 PM

hi

َAre you sour that id of second Dropdown is "Facts_sub_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