Details
Description
When creating an instance of Zend_Form_Element_File it does not render a description if set with setDescription.
E.g.
$image_file = $this->createElement('file', 'image_file')
->setLabel('Image file')
->setDescription('Select a image file to upload a new image. Image should be a gif, jpg or png image, less than 2mb in size.')
->addValidator('Count', false, 1)
->addValidator('Size', false, 1024*1024*2)
->addValidator('Extension', false, 'jpg,png,gif');
Does not display the description.
Looking at for code for Zend_Form_Element_File I can see why:
Line 71:
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('File')
->addDecorator('Errors')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
Its clear that this element does not get its default decorators from the parent... Any reason why?
Because files don't have a description until they are uploaded.
Feel free to use addDecorator() if you want to use decorators.