In the bootstrap:
//setup dojo
$view = new Zend_View;
Zend_Dojo::enableView($view);
$view->dojo()->setLocalPath('http://localhost/scripts/dojo/dojo/dojo.js')
->addStyleSheetModule('dijit.themes.tundra')
->disable();
In the action controller init() method:
Zend_Dojo::enableView($this->view);
$this->view->dojo()->enable();
The form class:
class Forms_AddUser extends Zend_Dojo_Form {
public function init() {
$this->setMethod('post');
$this->addElement(
'FilteringSelect',
'test_select',
array(
'label' => 'Label',
'multiOptions' => array(
'option1' => 'Option1',
'option2' => 'Option2'
)
)
);
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'forms/adduser.phtml'))
));
}
}
The view script decorator:
<form action="<?php echo $this->escape($this->element->getAction());
?>" method="<?php echo $this->escape($this->element->getMethod());
?>">
<?php echo $this->element->test_select; ?>
</form>
The layout script:
<?php echo $this->doctype( 'XHTML1_TRANSITIONAL'); ?>
<html>
<head>
<?php echo $this->headTitle(); ?>
<?php echo $this->headMeta(); ?>
<?php echo $this->headLink(); ?>
<?php echo $this->headStyle(); ?>
<?php
if($this->dojo()->isEnabled()) {
echo $this->dojo();
}
?>
<?php echo $this->headScript(); ?>
</head>
<body class="tundra">
<?php echo $this->layout()->content; ?>
</body>
</html>
I get the following HTML code as a result:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<title></title> <meta http-equiv="Content-Type"
content="text/html; charset=utf-8" /> <style
type="text/css">
<!--
@import "http://localhost/scripts/dojo/dijit/themes/tundra/tundra.css";
-->
</style>
<script type="text/javascript"
src="http://localhost/scripts/dojo/dojo/dojo.js"></script>
<script type="text/javascript">
//<![CDATA[
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.parser");
dojo.addOnLoad(function() {
dojo.forEach(zendDijits, function(info) {
var n = dojo.byId(info.id);
if (null != n) {
dojo.attr(n, dojo.mixin({ id: info.id }, info.params));
}
});
dojo.parser.parse();
});
var zendDijits =
[{"id":"test_select","params":{"dojoType":"dijit.form.FilteringSelect"}}];
//]]>
</script> </head>
<body class="tundra">
<form action="add" method="post">
<dt><label for="test_select" class="optional">Label</label></dt>
<dd>
<select name="test_select" id="test_select">
<option value="option1" label="Option1">Option1</option>
<option value="option2" label="Option2">Option2</option>
</select></dd></form>
...but both IE and Firefox show only the label and don't show the
filtering select at all. If I add more dojo elements to the form they
will show but as regular Zend_Form elements not Dojo.
ZendFramework 1.7.2
Dojo is from ZF externals
I would appreciate any advice.