How do I use ViewScripts on Zend_Form File Elements?

后端 未结 7 895
心在旅途
心在旅途 2020-11-29 02:43

I am using this ViewScript for my standard form elements:

element->getId(); ?>\"> <
相关标签:
7条回答
  • 2020-11-29 03:18

    I've found a work-around that avoids the ViewScript altogether.

    First, the element definition:

    $this->addElement('file', 'upload_file', array(
        'disableLoadDefaultDecorators' => true,
        'decorators' => array(
            'File',
            array(array('Value'=>'HtmlTag'), array('tag'=>'span','class'=>'value')),
            'Errors',
            'Description',
            'Label',
            array(array('Field'=>'HtmlTag'), array('tag'=>'div','class'=>'field file')),
        ),
        'label' => 'Upload File',
        'required' => false,
        'filters' => array('StringTrim'),
        'validators' => array(),
    ));
    

    Second, after the form class has been instantiated, I mimic the behavior of my ViewScript:

    $field = $form->getElement('upload_file');
    $decorator = $field->getDecorator('Field');
    $options = $decorator->getOptions();
    $options['id'] = 'field_' . $field->getId();
    if ($field->hasErrors()) {
        $options['class'] .= ' errors';
    }
    $decorator->setOptions($options);
    

    I guess that I should look into class-based decorators. Maybe there's more flexibility there?

    0 讨论(0)
提交回复
热议问题