How to add attributes (id for example) to options of Zend_Form_Element_Select?

风格不统一 提交于 2019-12-08 11:16:53

问题


I need to add custom attributes (id, class) to options of Zend_Form_Element_Select.

How can I do that?


回答1:


You can pass in an "attribs" array when instantiating the element. For example:

    $form->addElement('select', 'type', array(
        'label' => 'Label',
        'multioptions' => $some_array,
        'attribs' => array('class' => 'selector', 'id' => 'whatever')
    ));



回答2:


AFAIK it's not possible to add ids to select's options. Option would be implementing your own viewHelper and adding this functionality. But generally it's not possible.



来源:https://stackoverflow.com/questions/6397015/how-to-add-attributes-id-for-example-to-options-of-zend-form-element-select

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