Zend Form Украшения Проблемы - PullRequest
2 голосов
/ 27 января 2010

У меня есть несколько случайных проблем с материалами, связанными с декоратором, с Zend Form.

Во-первых,

    // THIS WORKS AND REMOVES THE DECORATORS
    $hidden = new Zend_Form_Element_Hidden('hiddenfield');
    $hidden->setRequired(TRUE)
           ->removeDecorator('label')
           ->removeDecorator('HtmlTag')
           ->addErrorMessage('Please 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');

Во-вторых, элемент формы, созданный так:

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

и добавлен в группу отображения следующим образом:

    // THIS DOESNT WORK
    $this->addDisplayGroup(array('comments'),'comments');
    $comms = $this->getDisplayGroup('comments');
    $comms->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            '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'
    ));

1 Ответ

2 голосов
/ 28 января 2010

Исправлена ​​проблема с displayGroup, содержащей элемент «comments». Очевидно, что группа отображения не может иметь того же имени, что и один из элементов формы, содержащихся внутри. Итак, решение было таким:

// 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'
));

и исправил другую проблему, удалив submit из массового addElements, где он был раньше, и индивидуально добавил его в форму, вручную удалив декораторы, например:

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

было бы интересно узнать, есть ли лучший способ, которым я мог бы сделать это.

...