Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Pages: 1
Bonjour,
J'essai d'implementer un autocomplete avec Zend Form. Et bien sur, encore un soucis de décorators. Pourtant, je fais bien ce que préconise la doc. Et j'ai cette erreur :
ZendX_JQuery_Form_Exception: Cannot render jQuery form element without at least one decorator implementing the 'ZendX_JQuery_Form_Decorator_UiWidgetElementMarker' interface. Default decorator for this marker interface is the 'ZendX_JQuery_Form_Decorator_UiWidgetElement'. Hint: The ViewHelper decorator does not render jQuery elements correctly. in /usr/share/php/libzend-framework-php/1/extras/library/ZendX/JQuery/Form/Element/UiWidget.php on
Il faut donc mettre le decorateur UiWidgetElement et c'est ce que je fais pourtant :
<?php
class Frontoffice_Form_Find extends Zend_Form {
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label',
array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
public $defaultDecorators =array(
'FormElements',
array('HtmlTag',
array('tag' => 'table','class' => 'zend_form responsive' )
),
'Form'
);
public function loadDefaultDecorators() {
$this->setDecorators($this->defaultDecorators);
$this->setElementDecorators ($this->elementDecorators);
}
public function init() {
$config = Zend_Registry::get('config');
$action = $this->getView()->url(array(), 'list_place');
$this->setMethod('post')
->setAction("#")
->setAttrib('id','geocoding_form')
->setAttrib('class','forms');
$address = new Zend_Form_Element_Text('ANN_ADRESSE_1');
$address->setLabel('address')
->addFilter('StripTags')
->addFilter('StringTrim')
->setAttrib('maxlength','255')
->setAttrib('title',Zend_Registry::get('Zend_Translate')->translate('tooltip choice address'))
->addValidator('notEmpty')
->getValidator('notEmpty')->setMessage('msg address');
///////////////////////////////////////////
// Add Autocomplete Element
$city = new ZendX_JQuery_Form_Element_AutoComplete(
"ac1", array('label' => 'Autocomplete:')
);
$city->setJQueryParams(array('source' => array('New York',
'Berlin',
'Bern',
'Boston')));
$city->setDecorators(
array(
'UiWidgetElement',
array('ViewScript', array('class' => 'RegElement'))
)
);
///////////////////////////////////////////
$submit = new Zend_Form_Element_Submit('submit');
$submit->setValue('Submit')
->setLabel('Valider')
->setAttrib('class','button')
->setDecorators($this->submitDecorators)
;
$this->addElements(array($address,$city,$submit));
}
}Dernière modification par __fabrice (18-04-2013 18:15:54)
Hors ligne
Bon, le problème vient des décorateurs "généraux" des éléments des formulaires :
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
public $defaultDecorators =array(
'FormElements',
array('HtmlTag', array('tag' => 'table','class' => 'zend_form responsive')),
'Form'
);
public $autocompleteDecorators = array(
array('UiWidgetElement', array('tag' => '')), // it necessary to include for jquery elements
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label',array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
public function loadDefaultDecorators() {
$this->setDecorators($this->defaultDecorators);
// $this->setElementDecorators($this->elementDecorators);
}si je dé-commente cette ligne
// $this->setElementDecorators($this->elementDecorators);
j'ai l'erreur, sinon, çà marche correctement (sans l'habillage qu'il faut, évidemment).
Donc, à priori, cela vient du décorateur des éléments du formulaire. Mais je vois pas..
Une idée ?
Merci
Fabrice
Hors ligne
Pages: 1