anon
anon

Reputation:

Yii: How to set dropDownList 'options' from array

I am using Yii 1.1.17. I would like to know how to add disabled option to the dropdown list from array. I know the way how to add options one by one

echo CHtml::tag('td', array('class' => 'row'),
    CHtml::dropDownList(
        'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
        $attr->C_FTYPE,
        TicketTypeAttribute::itemAlias('C_FTYPE'),
        [
            'options' => [
                'INT' => ['disabled' => 'disabled']
            ],
            'style' => 'width: 97%;',
            'class' => 'ftype'
        ]
    )
);

but is there a way to add it from array?

if($attr->C_FTYPE == 'DATETIME') {
    $disallow = ['DECIMAL', 'INT', 'BOOLEAN', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
} else {
    $disallow = ['INT', 'BOOLEAN', 'DECIMAL', 'DATETIME', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
}

Something like

echo CHtml::tag('td', array('class' => 'row'),
    CHtml::dropDownList(
        'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
        $attr->C_FTYPE,
        TicketTypeAttribute::itemAlias('C_FTYPE'),
        [
            'options' => [
                $disallow => ['disabled' => 'disabled']
            ],
            'style' => 'width: 97%;',
            'class' => 'ftype'
        ]
    )
);

Upvotes: 3

Views: 135

Answers (1)

Arth
Arth

Reputation: 13110

Easy enough to build the array yourself

$disallowed_options = [];

foreach($disallow as $option_key){
  $disallowed_options[$option_key] = ['disabled'=>'disabled'];
}

Then in your config

'options'=> $disallowed_options,

Upvotes: 1

Related Questions