dependent dropdown when edit in yii

不打扰是莪最后的温柔 提交于 2020-01-06 20:23:47

问题


Problem in dependent dropdowns when editing in my yii application. While editing, the drop downs are not automatically selected.

In my view,

array('class' => 'CButtonColumn',
    'header' => 'Manage',
    'template' => '{update} {view}  {delete}',
    'htmlOptions' => array('width' => '20%'),
    'buttons' => array(
        'update' => array(
            'label' => '',
            'imageUrl' => '',
            'options' => array('class' => 'glyphicon glyphicon-pencil'),
        ),
        'view' => array(
            'label' => '',
            'imageUrl' => '',
            'options' => array('class' => 'glyphicon glyphicon-eye-open'),
        ),
        'delete' => array(
            'label' => '',
            'imageUrl' => '',
            'options' => array('class' => 'glyphicon glyphicon-remove'),
        ),
    ),
),

回答1:


<div class="form-group">
    <label for="reg_input" class="req">Course</label>
    <?php
    $course = CHtml::listData(Course::model()->findAll(), 'courseid', 'course_name');
    echo CHtml::activeDropDownList($model, 'courseid', $course, array(
        'empty' => 'Select Course', 'class' => "form-control",
        'ajax' => array(
            'type' => 'POST',
            'url' => CController::createUrl('Assignment/Fetchbatch'),
            'update' => '#' . CHtml::activeId($model, 'batchid'))));
    ?>
    <?php echo $form->error($model, 'courseid', array('class' => 'school_val_error')); ?>  
</div>  
<div class="form-group">
    <label for="reg_input" class="req">Batch</label>
    <?php
     $batch = CHtml::listData(Batch::model()->findAll(), 'batchid', 'batch_name');
    echo $form->dropDownList($model, 'batchid', $batch, array('prompt' => 'Select Batch',
        'class' => "form-control",
        'ajax' => array(
            'type' => 'POST',
            'url' => CController::createUrl('Assignment/Fetchsubject'),
            'update' => '#' . CHtml::activeId($model, 'subjectid'))));
    echo $form->error($model, 'batchid', array('class' => 'school_val_error'));
    ?>
</div> 

Second dropdown get the data, to change of first dropdown. At this condition the dropdown will not be selected automatically. Because when editing, that value is not there. So I fixed this problem, my code is above this.



来源:https://stackoverflow.com/questions/31825161/dependent-dropdown-when-edit-in-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!