views:

287

answers:

2

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?

+1  A: 

If I understand the question correctly, then the answer is, it is impossible. See:

Gordon
Thanks, I was afraid of that. I've now worked around it by adding a decorator that uses jQuery to disable the radio button. Not very pretty, but combined with some server-side validation it works good enough.
Maarten Sander
@Maarten Come to think about it, why do you include the options if they are disabled at all? Can't you just not add them in the first place?
Gordon
@Gorden It's used in a questionnaire where certain questions have answers that have a maximum on it (e.g. "What's your preferred lunch timeslot?", where each timeslot has a max of 50 people). Instead of removing maxed out questions, my customer wants them disabled (since the can be re-enabled if someone changes her mind).
Maarten Sander
+1  A: 

Yes, it is possible:

$element->setMultiOptions(array (
 'songs' => 'songs',
 'lyrics' => 'lyrics',
 'artists' => 'artists'
));
$element->setAttrib('disable', array('lyrics', 'songs'));
ProfLogic
Thanks for the suggestion. I've not tried it out yet, but as soon as I have I'll let you know.
Maarten Sander