How can I append a description to a Zend_Form_Element?

Posted by Mallika Iyer on Stack Overflow See other posts from Stack Overflow or by Mallika Iyer
Published on 2010-04-26T16:30:49Z Indexed on 2010/04/26 16:33 UTC
Read the original article Hit count: 325

I have the following Zend_Form_Element:

   $imginstructions = "Some description";

    $img = $this->createElement('select','img');
    $img->setAttrib('class', 'image-select');
    $imgdecorator = $img->getDecorator('Description');
    $imgdecorator->setOption('escape', false);

    $img->setLabel('Image:')
        ->setRequired(true)
        ->addMultiOptions($images)
        ->setValue('')
        ->setDescription($imginstructions)
        ->addErrorMessage('You must select an image');

    $img->size = 5;
    $this->addElement($img);

The description should appear next to the select box. The problem is : When an error is thrown, the html rendered changes so the description shows up below the select box, instead of beside it.

HTML rendered before error is thrown:

 <dd id="img-element">
 <select size="5" class="image-select" id="img" name="img" style="display: none;">
   ...........options..............
 </select>
 <p class="description">Some Description</p></dd> 

HTML rendered after error is thrown:

 <dd id="img-element">
 <select size="5" class="image-select" id="img" name="img" style="display: none;">
   ...........options..............
 </select>
 <ul class="errors"><li>You must select an image</li></ul>
 <p class="description">Some Description</p></dd> 

Is there a way to force the error message to be appended as the last element in the DOM tree for the dd element?

Something like:

 <dd id="img-element">
 <select size="5" class="image-select" id="img" name="img" style="display: none;">
   ...........options..............
 </select>
 <p class="description">Some Description</p>
 <ul class="errors"><li>You must select an image</li></ul></dd> 

so the 'ul' is at the end of the dd DOM tree.

Thanks, I appreciate your taking the time to respond to this question!

© Stack Overflow or respective owner

Related posts about zend-form

Related posts about zend-form-element