$_disableLoadDefaultDecorators and ZendX_JQuery
-
21-04-2021 - |
سؤال
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?
المحلول
I have solved the problem. Any default decorators defined this way will also work on any ZendX_JQuery_Form_Element
IF
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.- There's no
AutoComplete
element inZend_Form
. So, the class you use to build your forms, that includes all your global settings and decorations (in my case:"My_Form"
) should extendZendX_JQuery_Form
, and notZend_Form
ZendX_JQuery_Form_Element_UiWidget
requiresUiWidgetElement
decorator. So we replace theViewHelper
decorator with ZendX_JQuery's:UiWidgetElement
.