Hi.
In this case,
$element->setDecorators('UserActiveRadio');
This will work provided the form can find the UserActiveRadio.php decorator
script.
In this case:
$form->addPrefixPath('My_Form_Decorator','My/Form/Decorator', 'decorator');
chinaski
chinaski wrote:
>
>
> chinaski wrote:
>>
>> I need some help with form decorator. I need help decorating a radio
>> group. Here is the group as defined in the init() method of my form
>> subclass:
>>
>> Appreciate help on setting the decorators for this element.
>>
>> Chinaski
>>
>>
>>
> I came up with a working solution, but it seems like an awful lot of work
> to get some html set up. I did a custom decorator for this particular
> situation, which looks like this.
>
> class My_Form_Decorator_UserActiveRadio extends
> Zend_Form_Decorator_Abstract
> {
> public function render($content)
> {
> $element = $this->getElement();
> if (!$element instanceof Zend_Form_Element_Multi) {
> return $content;
> }
> if (null === ($view = $element->getView())) {
> return $content;
> }
>
> $translator = $element->getTranslator();
>
> $html = '';
> $radio_selected_value = $element->getValue();
>
> $base_name = $element->getName();
>
> $html .= PHP_EOL . '<fieldset class="checks">';
> if ($element->isRequired()) {
> $html .= PHP_EOL . '<h5>' . $element->getLabel() .
> '<em>required</em></h5>';
> }
> $html .= PHP_EOL . '<ul>';
> $tmp = 0;
> foreach ($element->getMultiOptions() as $radio_value) {
> $tmp ++;
> $radio_id = $base_name . $tmp;
> $attribs = array('id'=>$radio_id);
> $options = array($values);
>
> $html .= PHP_EOL . '<li>' . PHP_EOL . '<input type="radio"
> name="' . $base_name . '" id="'
> . $radio_id . '" value="' . $radio_value . '" '
> . $this->is_checked($radio_value,$radio_selected_value) . '
> />'
> . PHP_EOL . '<label for="' . $radio_id . '">' . $radio_value .
> '</label>' . PHP_EOL . '</li>';
> }
> $html .= PHP_EOL . '</ul>' . PHP_EOL . '</fieldset><!--checks-->';
> return $html;
> }
>
> private function is_checked($option, $value)
> {
> if($option == $value) {
> return 'checked';
> }
> }
> }
>
> Setting this decorator on the element yields the proper html.
>
> If someone who is adept with the decorator stack can illustrate an easier
> way to accomplish the same thing, it would be appreciated.
>
>
--
View this message in context:
http://www.nabble.com/Zend_Form-Decorator-tp18270378p20863281.html
Sent from the Zend Framework mailing list archive at Nabble.com.