Question

I use my class to alter decoration of my form. In other words, instead of calling

Application_Form_Login extends Zend_Form

I use:

Application_Form_Login extends My_Form

In my "My_Form" class I define the following:

protected $_disableLoadDefaultDecorators = true;
protected $_elementDecorators = array(
   'ViewHelper',
   array(
      'Errors', 
      array(
         'data-icon'=>"alert", 
         'class'=>"ui-body ui-body-e errors"
      )
   ),
   'Label',
   array(
      array(
         'row' => "HtmlTag"
      ), array(
         'tag'=>"div", 
         'data-role'=>"fieldcontain"
      )
   )
);

This works perfect on my regular forms. But once I use jQuery forms:

$this->addElement(new ZendX_JQuery_Form_Element_AutoComplete(
   "ac1",
   array('label' => "Your Address:"))
));

It has no effect on them, and they still render with their default decorators. Any ideas how to globally set decorators for jQuery Form Elements as well?

Était-ce utile?

La solution

I have solved the problem. Any default decorators defined this way will also work on any ZendX_JQuery_Form_Element

IF

  1. The element is created inside of addElement function. In other words, instead of creating an element this way:

    $this->addElement(new ZendX_JQuery_Form_Element_AutoComplete(
        "address",
        array(
            'label' => "Your Address:"
        )
    ));
    

    You should create it this way:

    $this->addElement('AutoComplete', 'address', array(
        'label' => "Your Address:"
    ));
    

    Because when addElement creates the element itself, it will pass the default decorators to the creating function. Otherwise the elements will be created outside of the form context.

  2. There's no AutoComplete element in Zend_Form. So, the class you use to build your forms, that includes all your global settings and decorations (in my case: "My_Form") should extend ZendX_JQuery_Form, and not Zend_Form
  3. ZendX_JQuery_Form_Element_UiWidget requires UiWidgetElement decorator. So we replace the ViewHelper decorator with ZendX_JQuery's: UiWidgetElement.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top