zend form custom attribute in select option?

前端 未结 6 1077
慢半拍i
慢半拍i 2020-12-29 09:04

I want know how to add custom attribute for option in a select field of Zend form.

PHP:

$option_values = array(\"multiOptions\" => array(
    \"US         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 09:37

    mingos, you forgot about setvalue method of multiselect.

    you shoul add something like:

    ...
    foreach ($options as $opt_value => $option) {
                $opt_disable = '';
                $opt_selected = '';
                if (is_array($disable) && in_array($opt_value, $disable)) {
                    $opt_disable = ' disabled="disabled"';
                }
                if (in_array($opt_value,$value)) {
                    $opt_selected = ' selected="selected"';
                }
                $list[] = $this->_build($option, $disabled, $opt_selected);
            }
    ...
    and
    
    protected function _build($option, $disabled, $opt_selected) {
            $html = ' $value) {
                $html .= " $attrib=\"$value\"";
            }
            return $html . $disabled . $opt_selected . " foo>" . $option['label'] . "";
        }
    

提交回复
热议问题