3

我正在创建一个多复选框,然后用循环填充它。是否可以在之后或填充过程中禁用其中一个复选框?

$multiOptions = array();
$multiCheckbox = new Zend_Form_Element_MultiCheckbox('multi_name', $multiOptions);
foreach($valuesArray AS $value) {
    $name = $this->getName($value);
    $multiCheckbox->addMultiOption($name, $value);
}

我试图通过下面的代码禁用一个复选框,但它不起作用。有人有更好的建议吗?

$multiCheckbox->setAttrib('disable', $this->getName($valuesArray[2]));

这也无济于事:

$multiCheckbox->setAttrib('disable', $valuesArray[2]);

带有值的数组只是一个简单的数组:

$valuesArray(1, 2, 3, 4, 5);
4

1 回答 1

0

You will want to create a new view helper to so that you can set the disabled attribute of the element when it is displayed.

The current view helper code looks like this:

public function formMultiCheckbox($name, $value=null, $attribs=null, $options=null, $listsep="<br />\n") {
    return $this->formRadio($name, $value, $attribs, $options, $listsep);
}

You should be able to set an 'disabledElement' option when you are creating your multicheckbox and then in your view helper check if the checkbox being displayed should be disabled or not.

public function formMultiCheckbox($name, $value=null, $attribs=null, $options=null, $listsep="<br />\n") {
    $disableElements = $options['disableElement']; 

    if(in_array($name, $disableElements, true)) {
        $options['disable'] => true;
    }

    return $this->formRadion($name, $value, $attribs, $options, $listsep);
}

Overriding the view helper to check which elements should be disabled and then setting the option should work.

You may want to extend the Form_Element_MultiCheckbox into your own class and creating the view helper for that element yourself. Based on the Zend Framework manual

于 2013-06-11T14:38:58.577 回答