Zend Framework

Zend_Form_Element_File does not include Description decorator

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.6
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Form
  • Labels:
    None

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?

Activity

Hide
Thomas Weidner added a comment -

Because files don't have a description until they are uploaded.
Feel free to use addDecorator() if you want to use decorators.

Show
Thomas Weidner added a comment - Because files don't have a description until they are uploaded. Feel free to use addDecorator() if you want to use decorators.
Hide
Al James added a comment -

Hmmm... Why does a file not have a description until its uploaded? What if I want to add a description of the form "Please make your file a jpg,gif or png less that 1mb in size"?

Show
Al James added a comment - Hmmm... Why does a file not have a description until its uploaded? What if I want to add a description of the form "Please make your file a jpg,gif or png less that 1mb in size"?
Hide
Thomas Weidner added a comment -

Integrated with r14234

Show
Thomas Weidner added a comment - Integrated with r14234

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: