oligalma
(Marc Oliveras)
November 1, 2014, 7:36pm
1
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
wadeshuler
(Wadeshuler)
November 5, 2014, 10:15am
2
It may be dumb, but are you sure jQuery is loaded? Make sure it is loaded, and check the error console for errors.
oligalma
(Marc Oliveras)
November 5, 2014, 7:06pm
3
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
Bizley
(Bizley)
November 6, 2014, 6:39am
4
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?
oligalma
(Marc Oliveras)
November 6, 2014, 8:37pm
5
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>";
}
Bizley
(Bizley)
November 7, 2014, 6:38am
6
Check if code responsible for loading the content is present. Look for any potential errors in the console (use Firebug or other similar tool).
Hi,
can u show ur dependentcontroller’s action code ,and ur dropdown list code…so we can exactly find out solution.
oligalma
(Marc Oliveras)
November 8, 2014, 5:07am
8
<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>
Bizley
(Bizley)
November 8, 2014, 12:00pm
9
Is your $model class called Facts?
negar
(Nar8591)
November 9, 2014, 4:49am
11
hi
َAre you sour that id of second Dropdown is "Facts_sub_category" ??