Timmeh
Timmeh

Reputation: 135

decorating Zend_Form_Element_MultiCheckbox in a unordered list

I need to decorate to Zend_Form_Element_MultiCheckbox into a unordered list, I can get each item surround by <li>, by setting setSeparator to </li><li> and the HtmlTag tag to <li>

I just get find anything to set the <ul> around this list, anyone able to point me in the right direction?

Thanks for reading (My code is below)

  $interests = new Zend_Form_Element_MultiCheckbox('foo');
  $interests->setSeparator('</li><li>');

  foreach ($interestsTable->findForSelect() as $interest) { // For earch interest add an option
      $interests->addMultiOption($interest->interest_id, $interest->interest);
  }

  // Decorate the interests
  $interests->setDecorators(array(
   array('ViewHelper'),
   array('label', array(
   'tag' => 'span'   )),
   array('HtmlTag', array(
   'tag' => 'li', 'class' => 'interestOption'))
  ));

Upvotes: 1

Views: 3333

Answers (1)

Steve Hill
Steve Hill

Reputation: 2321

I can't give you any code that will work off the top of my head, but, from reading the docs, it's clear that you can re-use decorators as many times as you need to. You just need to specify a new name for them.

Look at: http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.decorators, specifically the section titled "Using Multiple Decorators of the Same Type".

Based on that, the below might work (but I haven't tested it, it could be in the wrong order or anything):

$interests->setDecorators(
    array(
        array('ViewHelper'),
        array('label', array( 'tag' => 'span' )),
        array('HtmlTag', array( 'tag' => 'li', 'class' => 'interestOption')),
        array(
            'decorator' => array('LiTag' => 'HtmlTag'),
            'options' => array('tag' => 'ul')
        )
    )
);

Upvotes: 1

Related Questions