Zend元素 - 如何禁用特定的选择/下拉列表

时间:2017-02-16 04:35:24

标签: php zend-framework drop-down-menu

正如标题所说,我在网上使用以下代码选择/下拉列表

<?php
class Application_Form_Element_BranchDropdownDisabled extends Zend_Form_Element_Select {
    public function init() {
        $branch = new Application_Model_DbTable_Branch();
        $this->addMultiOption(0, ' ');
        foreach ($branch->fetchAll() as $branch) {
            if($branch['disabled']==false){
                $this->addMultiOption($branch['branch_id'], $branch['branch_name']);
            }else{
                //i want to add multioption but disabled
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

Both ZF! and Zf2 doesn't provide a way to disable specific option on select/dropdown list. So you have to do it using javascript. So add a class to disabled options and disable it by js.

<select>
  <option value="Opt 1">Opt 1</option>
  <option class="disabledOption" value="Disabled value">Disabled option</option>
</select>

$(".disabledOption").attr("disabled", "disabled");