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



如标题所示,我在网络上使用以下代码进行了选择/下拉列表

<?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
            }
        }
    }
}
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");

最新更新