开发者

Using Zend Form and Dojo without using ZF MVC

for our applications we use Zend_form, without any part of the ZF MVC stack. We would like to make dynamics forms (Javascript, Ajax powered), we are looking Dojo, but it does not working "out of the box". Online Zend Framework documentation did not help, because all examples talk about Zend_Form on MVC applications.

Where is our error? What are we missing? Here is the code :

$oViewZF = new Zend_View();
Zend_Dojo::enableView($oViewZF);
$oViewZF->addHelperPath(PATH_ZF . '1.11.4/library/Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper');
$oViewZF->dojo()->setCdnVersion('1.1.1');
$oViewZF->dojo()->setLocalPath('dojo/dojo/dojo.js')->addStyleSheetModule('dijit.themes.tundra');

$form = new Zend_Dojo_Form();
$form->setAction($url)->setMethod('post')->setTranslator(self::ZendFormTranslate());
$form->addPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/')
       ->addElementPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/')
       ->addDisplayGroupPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/');
$form->setDecorators(array('FormElements', array('TabContainer', array('id' => 'tabContainer', 'style' =>
'width: 600px; height: 500px;', 'dijitParams' => array('tabPosition' => 'top'))), 'DijitForm'));

echo $oViewZF->headScript(); #show nothing
echo $oViewZF->dojo(); #print "style @import dojo/dijit/themes/tundra/tundra.css"; and <script type="text/javascript" src="dojo/dojo/dojo.js"></script>
echo $oViewZF->layout()->content; #show nothing
echo $oViewZF->inlineScript(); #show nothing

$birthday = new Zend_Dojo_Form_Element_DateTextBox('birthday');
$birthday->setLabel('Birthday');
$form->addElement($birthday);
$form->addElement('submit', 'cmd', array('label' => 'Créer'));
echo $form->render($oViewZF);

It show only a text imput field without any JS error :

开发者_如何学Python<dt id="birthday-label"><label for="birthday" class="optional">Birthday</label></dt>
<dd><input id="birthday" name="birthday" value="" type="text"></dd>

We would like to use date pickers, fields only required/visibles when a checkbox is checked, and so on.

Regards,

Cédric

ps: if I place the $oViewZF->Dojo() (see Zend_Dojo_Form in a layout) after the render() call, I have this JS error

Erreur : uncaught exception: [Exception... "String contains an invalid character" code: "5" nsresult: "0x80530005 (NS_ERROR_DOM_INVALID_CHARACTER_ERR)" location: "http://127.0.0.1/~cedric/EC/VOOELFE/code/decideur/public/dojo/dojo/_base/_loader/bootstrap.js Line: 1930"]


Ok, here is the answer :

$oViewZF = new Zend_View();

Zend_Dojo::enableView($oViewZF);
$oViewZF->addHelperPath(CHEMIN_ZF . '1.11.4/library/Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper');
$oViewZF->dojo()->setLocalPath('dojo/dojo/dojo.js')->addStyleSheetModule('dijit.themes.tundra');

$form->addPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/') 
    ->addElementPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/') 
    ->addDisplayGroupPrefixPath('Zend_Dojo_Form', 'Zend/Dojo/Form/');

echo $form->render($oViewZF);
echo $oViewZF->dojo();
echo $oViewZF->inlineScript();

The dojo() call must be after the render() call, and one of my fields was badly declared and created the JS error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜