Zend装饰器:如何在表单上使用jquery-ui类?

时间:2011-08-04 15:41:53

标签: jquery-ui zend-framework zend-form zendx

我使用jquery在Zend Framework中创建一个表单:

    class Contact_Form_Contact extends ZendX_JQuery_Form {

  public function init() {
        /* Form Elements & Other Definitions Here ... */
        //create new element
        $name = $this->createElement('text', 'name');
        //element options
        $name->setLabel("Enter your name:");
        $name->setRequired(TRUE);
        $name->setAttrib('size', 40);
        //add element to the form

        $this->addElement($name);
        .....

如果请求失败,则setRequired启用class = errors,

如何将其覆盖为“ui-state-error my-clean”?

阿尔曼。

2 个答案:

答案 0 :(得分:3)

您可以通过以下方式设置装饰器选项,而不是覆盖装饰器:

$element->getDecorator('Errors')->setOption('class', 'ui-state-error my-clean')

答案 1 :(得分:2)

在认真阅读Zend的博客之后,我发现装饰者很容易做到这一点:

  $this->setElementDecorators(array(
        'ViewHelper',
        'Label',
        array('Errors', array('class'=>'ui-state-error'))
    ));