Is it possible to disable individual options in a Zend_Form_Element_Radio
? That is, I'd like to add disabled="disabled"
to certain input tags.
Does the Zend Framework include this functionality? Or is there another way to accomplish this?
Is it possible to disable individual options in a Zend_Form_Element_Radio
? That is, I'd like to add disabled="disabled"
to certain input tags.
Does the Zend Framework include this functionality? Or is there another way to accomplish this?
Yes, it is possible:
$element->setMultiOptions(array (
'songs' => 'songs',
'lyrics' => 'lyrics',
'artists' => 'artists'
));
$element->setAttrib('disable', array('lyrics', 'songs'));
It works best on the option-key. Here is a function for disabling every option except the currently active one:
/**
* This function disables all options of the given selectElement, except for the active one
* @param \Zend_Form_Element_Select $selectElement
* @throws \Zend_Form_Exception
*/
private function disableAllOtherOptions(\Zend_Form_Element_Select $selectElement)
{
$theOneAndOnlyActiveValue = $selectElement->getValue();
$optionsToDisable = [];
foreach ($selectElement->options as $key => $option) {
if ($key <> $theOneAndOnlyActiveValue) {
$optionsToDisable[] = $key;
}
}
$selectElement->setAttrib('disable', $optionsToDisable);
}
© 2022 - 2024 — McMap. All rights reserved.