You should be using dojo selects in the first place, I have a working
example (4files):
file index.phtml (in scripts/ directory)
<?php echo $this->doctype() ?>
<html>
<head>
<?php echo $this->headTitle() ?>
<?php echo $this->headMeta() ?>
<?php echo $this->headLink() ?>
<?php echo $this->headStyle() ?>
<?php
$this->dojo()->setLocalPath('/zf/js/dojo/dojo.js')
->addStyleSheetModule('dijit.themes.tundra');
echo $this->dojo()->enable();
echo $this->headScript();
?>
</head>
<body class="tundra">
<?php echo $this->form ?>
<?php echo $this->inlineScript() ?>
</body>
</html>
//following files in root directory
file index.php:
<?php
require_once 'autoload.php';
$view = new Zend_View();
Zend_Dojo::enableView($view);
$form = new Zend_Dojo_Form('myform');
$form->setView($view);
$autoComplete1 = new Zend_Dojo_Form_Element_FilteringSelect('sel_1');
//$autoComplete1 = new Zend_Form_Element_Select('sel_1');
$autoComplete1->setMultiOptions(
array('Cats', 'Dogs')
);
$autoComplete1->setAttrib('onchange', "dijit.byId('sel_2').searchAttr =
dijit.byId('sel_1').getValue();return true");
$autoComplete1->setLabel('Select 1');
$form->addElement($autoComplete1);
$searchAttribute = @$_GET['sel_1'];
if( ! in_array($searchAttribute, array('0', '1'))){
$searchAttribute = '0';
}
$form->addElement(
'FilteringSelect',
'sel_2',
array(
'label' => 'Select 2',
'storeId' => 'myData',
'storeType'=> 'dojo.data.ItemFileReadStore',
'storeParams' => array( 'url' => '/zf/dojo.php',),
'dijitParams' => array( 'searchAttr' => $searchAttribute, ),
)
);
$form->addElement('submit','go');
$form->populate($_GET);
$view->form = $form->render();
$view->addBasePath('E:\werk\zf fixes\testsite');
echo $view->render('index.phtml');
?>
file dojo.php:
<?php
require_once 'autoload.php';
$data = new Zend_Dojo_Data();
$data->setIdentifier('name');
$cats = array('Lion', 'Cheeta', 'Cat');
foreach ($cats as $key => $cat) {
$data->addItem(array('name' => $key, '0' => $cat));
}
$dogs = array(3 => 'Bello', 4 => 'Blix', 5 => 'Freddy', 6 => 'Hungry
Bill');
foreach ($dogs as $key => $dog) {
$data->addItem(array('name' => $key,"1" => $dog));
}
echo $data;
file autoload.php: (depecated)
<?php
require_once 'Zend/Loader.php';
/**
* Loads all Zend Framework classes automagically
*
* @param string $className
*/
function __autoload($className){
Zend_Loader::loadClass($className);
}
?>
Hope this helps,
Bart
411161 schreef:
Ace Paul wrote:
I have a form, which I would like to use dependent drop downs in. I can't
seem to find anything about it hear, after looking all morning trying to
work it out.
I have one field "race_country"
when an option is selected I would like to show the cities in that
country.
The following is what I have currently in the form, which will show all
countries and all cities.
Any help would be great. thanks
$table = new Country();
foreach ($table->fetchAll() as $c) {
$country->addMultiOption($c->country_id, $c->country_name);
}
$this->addElement( $country);
$city = new Zend_Form_Element_Select('race_city');
$city->setLabel('City')
->setRequired(true);
$table = new City();
foreach ($table->fetchAll() as $c) {
$city->addMultiOption($c->city_id, $c->city_name);
}
$this->addElement( $city);
Does anyone have a complete example of this?
I used this example to get it up and going:
http://techchorus.net/autocomplete-example-zenddojoformelementfilteringselect-and-zenddojodata
With the change located in the comments:
<div dojoType="dojo.data.ItemFileReadStore" url="/strain/list"
jsId="strainStore"></div>
but I am having trouble trying to do dependent drop downs. Any good
references out there, or is this too early to attempt with Zend & Dojo?