开发者

Zend Form Decoration Issues

I've got a few random issues with decorator related stuff with Zend Form.

Firstly,

    // THIS WORKS AND REMOVES THE DECORATORS
    $hidden = new Zend_Form_Element_Hidden('hiddenfield');
    $hidden->setRequired(TRUE)
           ->removeDecorator('label')
           ->removeDecorator('HtmlTag')
           ->addErrorMessage('Ple开发者_JS百科ase upload something');

    // BUT IT DOESNT WORK HERE - THE DECORATORS ARENT REMOVED
    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setLabel('Proceed to Part 2 of 2')
           ->removeDecorator('label')
           ->removeDecorator('HtmlTag')
           ->setAttrib('class', 'button fleft cta');

Secondly, a form element created like this:

    $comments = new Zend_Form_Element_Textarea('comments');
    $comments->setLabel('Any comments')
             ->setRequired(FALSE);

and added to a display group like this:

    // THIS DOESNT WORK
    $this->addDisplayGroup(array('comments'),'comments');
    $comms = $this->getDisplayGroup('comments');
    $comms->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));

isnt added to a Fieldset but a custom form element using the same code is added to its own fieldset:

    // THIS WORKS!
    $this->addDisplayGroup(array('custom'),'custom',array('legend'=>'Legend Here'));
    $swfupload = $this->getDisplayGroup('swfupload');
    $swfupload->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Fieldset'
    ));


Fixed the issue with the displayGroup containing the "comments" element. Evidently its not possible for a display group to have the same name as one of the form elements contained within. So the solution was this:

// THIS DOESNT WORK
$this->addDisplayGroup(array('comments'),'comments');
$comms = $this->getDisplayGroup('comments');
$comms->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Fieldset'
));

// THIS NOW WORKS
$this->addDisplayGroup(array('comments'),'commentsbox'); // change here
$comms = $this->getDisplayGroup('commentsbox'); // change here
$comms->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Fieldset'
));

and fixed the other issue by removing submit from the mass addElements where it was before and individually added it to the form, manually removing the decorators like this:

    $this->addElement($submit);
    $submit->setDecorators(array(
        array('ViewHelper'),
        array('Description'),
        array('HtmlTag')
    ));

would be interested to hear if there was a better way i could have done this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜