Reputation:
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?
Upvotes: 9
Views: 2951
Reputation: 155
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);
}
Upvotes: 0
Reputation: 234
Yes, it is possible:
$element->setMultiOptions(array (
'songs' => 'songs',
'lyrics' => 'lyrics',
'artists' => 'artists'
));
$element->setAttrib('disable', array('lyrics', 'songs'));
Upvotes: 21