Search code examples
drop-down-menuyiiselected

yii method to disable selected options from multi select dropdown


I am using Yii dropdown with active records in that I am using a multiselect dropdown. I am creating data with in which I am selected multiple options from the dropdown. While updating I want to disable selected options which I selected at time of creation.

<code>
<?php 
$savedSections  =   helpers::getQuestionnaireSectionList($model->questionnaire_id);

$data   =   helpers::getSection();

$listData       =   CHtml::listData($data, 'section_id', 'section_name');

$htmlOptions = array('size' => '5', 'multiple' => 'true','style'=>'width: 333px');

$queSection->section_ref_id =   $savedSections; #sec2

echo $form->listBox($queSection,'section_ref_id',$listData, $htmlOptions); #sec1

?>

<code>

Now here #sec1 is showing output with multiple options and I am also getting selected options but I want to disable all the selected options which are coming from #sec2

Please help me if you have any ideas.


Solution

  • change your $htmlOptions to be like this:

    $htmlOptions = array(
        'size' => '5',
        'multiple' => 'true',
        'options'=>array(45=>array('disabled'=>'disabled')),
    );
    

    45 here is a section_id

    and if you want to find out how it's implemented you can take a look a this https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php#L2516