RE: [fw-general] How to set up dependant dropdowns in form

2009-04-28 Thread Anthony Smith
Thanks Brad.

 

Now I had one other question. Let's say my data looks like this:

{identifier:TERRITORY,items:[

{SUB:8-8-19-6,TERRITORY:8-8-19-66-1-3-25},

{SUB:8-8-19-6,TERRITORY:8-8-19-66-1-2-24}, ..

 

Instead of this:

{identifier:name,items:[

{name:0,0:Lion},

{name:1,0:Cheeta},

{name:2,0:Cat}, ...

 

 

I want to USE the SUB values to get the values for the TERRITORY. How do
I do that? 



From: Bart McLeod [mailto:mcl...@spaceweb.nl] 
Sent: Monday, April 27, 2009 11:22 AM
To: 411161
Cc: fw-general@lists.zend.com
Subject: Re: [fw-general] How to set up dependant dropdowns in form

 

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-zenddojoformelementfilterings
elect-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?
 
  


Re: [fw-general] How to set up dependant dropdowns in form

2009-04-27 Thread 411161



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?

-- 
View this message in context: 
http://www.nabble.com/How-to-set-up-dependant-dropdowns-in-form-tp20907379p23259776.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] How to set up dependant dropdowns in form

2009-04-27 Thread Bart McLeod
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?

  


Re: [fw-general] How to set up dependant dropdowns in form

2008-12-14 Thread Ace Paul

thanks for your help on this.
I'm trying to get this going, but not having any luck at all, especially
seeing as I haven't used json with zend yet.

I'm getting this error in my controller file.

Method encodeJson does not exist and was not trapped in __call() 
   public function _prepareautocompletion($data) {
$items = array();
foreach ($data as $key = $value) {
$items[] = array('label' = $value, 'name' = $value, 'key' =
$key);
}
$final = array(
'identifier' = 'key',
'items' = $items,
);
return $this-encodeJson($final);
}

this is my autocompleteAction in CategoryController.php

  function autocompleteAction () 
{
$this-getHelper('viewRenderer')-setNoRender();
$request = $this-getRequest();
$category_id = (int)$this-_request-getParam('category_id');
$race = new Race();
$races = $race-getCategoryRaces($category_id); // function to 
output all
races
$this-view-races = $this-_prepareautocompletion($races);
}


Ok, now theres a couple things here i'm unsure of.
Firstly because this is setup with the first select box not populated
because it is expecting data from a data store, how am I to pass this info
into the json request. I'm sure I'm way off track with this one.
And Second, why am I getting the json error. Do I need to set something up
before hand for this to work.

thanks
Paul 


Themselves wrote:
 
 I have spent WAY too much time getting this exact scenario working using
 Zend Dojo forms and an MVC environment, and I plan on building an
 extensive
 article explaining it all soon, but for now, here's the really quick and
 dirty version. I haven't gotten my version perfect yet, I'm still not
 happy
 with the URLs I'm calling to retrieve the data, but that's not a huge
 deal.
 Anyway, on with the show.
 
 First of all, here's your two form elements.
 
 $this-addElement('FilteringSelect', 'fk_client_id', array(
 'label'= 'Client:',
 'storeId' = 'clientStore',
 'storeType'= 'dojo.data.ItemFileReadStore',
 'storeParams' = array( 'url' =
 '/clients/autocomplete/format/ajax?autocomplete=1str=*',),
 'autoComplete'   = 'false',
 'hasDownArrow'   = 'true',
 'id' = 'fk_client_id',
 ));
 
 $this-addElement('FilteringSelect', 'fk_client_contact_id',
 array(
 'label'= 'Client contact:',
 'storeId' = 'clientContactStore',
 'storeType'= 'dojo.data.ItemFileReadStore',
 'autoComplete'   = 'false',
 'hasDownArrow'   = 'true',
 'id' = 'fk_client_contact_id',
 ));
 
 Now for the javascript, this has to appear somewhere on the page that
 contains the form.
 
 dojo.connect(dijit.byId('fk_client_id'), 'onChange', function () {
 dijit.byId('fk_client_contact_id').store = new
 dojo.data.ItemFileReadStore({ url:
 /clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id= +
 dijit.byId(fk_client_id).value });
 });
 
 
 As for the URLs for the Datastores, they are kind of an exercise for the
 reader, other than to say they obviously should filter correctly on the
 passed parameters, and they have to return JSON. This part was pretty
 annoying, but I eventually found that a function like this returns the
 correct JSON format:
 
 public function prepareAutoCompletion($data) {
 $items = array();
 foreach ($data as $key = $value) {
 $items[] = array('label' = $value, 'name' = $value, 'key' =
 $key);
 }
 $final = array(
 'identifier' = 'key',
 'items' = $items,
 );
 return $this-encodeJson($final);
 }
 
 
 You pass in to the function an array of id = value pairs, and it will
 output the correct JSON for the FilteringSelects. If you use the built in
 AutoCompleteDojo helper, it won't use the id from your table as the value
 that the form submits, which is pretty much useless.
 
 Oh, and one more trick, for the Edit action, you are going to need to
 include something like this:
 
 $form-populate($row);
 $form-getElement('fk_client_contact_id')-setStoreParams(array( 'url' =
 '/clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id=' .
 $form-getElement('fk_client_id')-getValue() ));
 
 So that it prepopulates the form correctly.
 
 I promise I'll write up a really impressive document that spells this
 whole
 thing out in painstaking detail, I'm just absolutely flat out until
 christmas, I haven't had any time!
 
 
 On Tue, Dec 9, 2008 at 10:58 AM, Ace Paul sa...@acewebdesign.com.au
 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 

Re: [fw-general] How to set up dependant dropdowns in form

2008-12-14 Thread Cameron
try calling it statically, Zend_Json::encode($data);

On Sun, Dec 14, 2008 at 11:39 PM, Ace Paul sa...@acewebdesign.com.auwrote:


 thanks for your help on this.
 I'm trying to get this going, but not having any luck at all, especially
 seeing as I haven't used json with zend yet.

 I'm getting this error in my controller file.

 Method encodeJson does not exist and was not trapped in __call()
   public function _prepareautocompletion($data) {
$items = array();
foreach ($data as $key = $value) {
$items[] = array('label' = $value, 'name' = $value, 'key' =
 $key);
}
$final = array(
'identifier' = 'key',
'items' = $items,
);
return $this-encodeJson($final);
}

 this is my autocompleteAction in CategoryController.php

  function autocompleteAction ()
{
$this-getHelper('viewRenderer')-setNoRender();
$request = $this-getRequest();
$category_id =
 (int)$this-_request-getParam('category_id');
$race = new Race();
$races = $race-getCategoryRaces($category_id); // function
 to output all
 races
 $this-view-races = $this-_prepareautocompletion($races);
}


 Ok, now theres a couple things here i'm unsure of.
 Firstly because this is setup with the first select box not populated
 because it is expecting data from a data store, how am I to pass this info
 into the json request. I'm sure I'm way off track with this one.
 And Second, why am I getting the json error. Do I need to set something up
 before hand for this to work.

 thanks
 Paul


 Themselves wrote:
 
  I have spent WAY too much time getting this exact scenario working using
  Zend Dojo forms and an MVC environment, and I plan on building an
  extensive
  article explaining it all soon, but for now, here's the really quick and
  dirty version. I haven't gotten my version perfect yet, I'm still not
  happy
  with the URLs I'm calling to retrieve the data, but that's not a huge
  deal.
  Anyway, on with the show.
 
  First of all, here's your two form elements.
 
  $this-addElement('FilteringSelect', 'fk_client_id', array(
  'label'= 'Client:',
  'storeId' = 'clientStore',
  'storeType'= 'dojo.data.ItemFileReadStore',
  'storeParams' = array( 'url' =
  '/clients/autocomplete/format/ajax?autocomplete=1str=*',),
  'autoComplete'   = 'false',
  'hasDownArrow'   = 'true',
  'id' = 'fk_client_id',
  ));
 
  $this-addElement('FilteringSelect', 'fk_client_contact_id',
  array(
  'label'= 'Client contact:',
  'storeId' = 'clientContactStore',
  'storeType'= 'dojo.data.ItemFileReadStore',
  'autoComplete'   = 'false',
  'hasDownArrow'   = 'true',
  'id' = 'fk_client_contact_id',
  ));
 
  Now for the javascript, this has to appear somewhere on the page that
  contains the form.
 
  dojo.connect(dijit.byId('fk_client_id'), 'onChange', function () {
  dijit.byId('fk_client_contact_id').store = new
  dojo.data.ItemFileReadStore({ url:
  /clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id= +
  dijit.byId(fk_client_id).value });
  });
 
 
  As for the URLs for the Datastores, they are kind of an exercise for the
  reader, other than to say they obviously should filter correctly on the
  passed parameters, and they have to return JSON. This part was pretty
  annoying, but I eventually found that a function like this returns the
  correct JSON format:
 
  public function prepareAutoCompletion($data) {
  $items = array();
  foreach ($data as $key = $value) {
  $items[] = array('label' = $value, 'name' = $value, 'key'
 =
  $key);
  }
  $final = array(
  'identifier' = 'key',
  'items' = $items,
  );
  return $this-encodeJson($final);
  }
 
 
  You pass in to the function an array of id = value pairs, and it will
  output the correct JSON for the FilteringSelects. If you use the built in
  AutoCompleteDojo helper, it won't use the id from your table as the value
  that the form submits, which is pretty much useless.
 
  Oh, and one more trick, for the Edit action, you are going to need to
  include something like this:
 
  $form-populate($row);
  $form-getElement('fk_client_contact_id')-setStoreParams(array( 'url' =
  '/clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id='
 .
  $form-getElement('fk_client_id')-getValue() ));
 
  So that it prepopulates the form correctly.
 
  I promise I'll write up a really impressive document that spells this
  whole
  thing out in painstaking detail, I'm just absolutely flat out until
  christmas, I haven't had any time!
 
 
  On Tue, Dec 9, 2008 at 10:58 AM, Ace Paul sa...@acewebdesign.com.au
  wrote:
 
 
  I have a form, which I 

Re: [fw-general] How to set up dependant dropdowns in form

2008-12-09 Thread Ace Paul

Thank you very much for the reply. I have been looking high and low for a
solution.
I will let you know how I go with this. 
Thanks


Themselves wrote:
 
 I have spent WAY too much time getting this exact scenario working using
 Zend Dojo forms and an MVC environment, and I plan on building an
 extensive
 article explaining it all soon, but for now, here's the really quick and
 dirty version. I haven't gotten my version perfect yet, I'm still not
 happy
 with the URLs I'm calling to retrieve the data, but that's not a huge
 deal.
 Anyway, on with the show.
 
 First of all, here's your two form elements.
 
 $this-addElement('FilteringSelect', 'fk_client_id', array(
 'label'= 'Client:',
 'storeId' = 'clientStore',
 'storeType'= 'dojo.data.ItemFileReadStore',
 'storeParams' = array( 'url' =
 '/clients/autocomplete/format/ajax?autocomplete=1str=*',),
 'autoComplete'   = 'false',
 'hasDownArrow'   = 'true',
 'id' = 'fk_client_id',
 ));
 
 $this-addElement('FilteringSelect', 'fk_client_contact_id',
 array(
 'label'= 'Client contact:',
 'storeId' = 'clientContactStore',
 'storeType'= 'dojo.data.ItemFileReadStore',
 'autoComplete'   = 'false',
 'hasDownArrow'   = 'true',
 'id' = 'fk_client_contact_id',
 ));
 
 Now for the javascript, this has to appear somewhere on the page that
 contains the form.
 
 dojo.connect(dijit.byId('fk_client_id'), 'onChange', function () {
 dijit.byId('fk_client_contact_id').store = new
 dojo.data.ItemFileReadStore({ url:
 /clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id= +
 dijit.byId(fk_client_id).value });
 });
 
 
 As for the URLs for the Datastores, they are kind of an exercise for the
 reader, other than to say they obviously should filter correctly on the
 passed parameters, and they have to return JSON. This part was pretty
 annoying, but I eventually found that a function like this returns the
 correct JSON format:
 
 public function prepareAutoCompletion($data) {
 $items = array();
 foreach ($data as $key = $value) {
 $items[] = array('label' = $value, 'name' = $value, 'key' =
 $key);
 }
 $final = array(
 'identifier' = 'key',
 'items' = $items,
 );
 return $this-encodeJson($final);
 }
 
 
 You pass in to the function an array of id = value pairs, and it will
 output the correct JSON for the FilteringSelects. If you use the built in
 AutoCompleteDojo helper, it won't use the id from your table as the value
 that the form submits, which is pretty much useless.
 
 Oh, and one more trick, for the Edit action, you are going to need to
 include something like this:
 
 $form-populate($row);
 $form-getElement('fk_client_contact_id')-setStoreParams(array( 'url' =
 '/clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id=' .
 $form-getElement('fk_client_id')-getValue() ));
 
 So that it prepopulates the form correctly.
 
 I promise I'll write up a really impressive document that spells this
 whole
 thing out in painstaking detail, I'm just absolutely flat out until
 christmas, I haven't had any time!
 
 
 On Tue, Dec 9, 2008 at 10:58 AM, Ace Paul [EMAIL PROTECTED]
 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);
 --
 View this message in context:
 http://www.nabble.com/How-to-set-up-dependant-dropdowns-in-form-tp20907379p20907379.html
 Sent from the Zend Framework mailing list archive at Nabble.com.


 
 

-- 
View this message in context: 
http://www.nabble.com/How-to-set-up-dependant-dropdowns-in-form-tp20907379p20910287.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] How to set up dependant dropdowns in form

2008-12-08 Thread Cameron
I have spent WAY too much time getting this exact scenario working using
Zend Dojo forms and an MVC environment, and I plan on building an extensive
article explaining it all soon, but for now, here's the really quick and
dirty version. I haven't gotten my version perfect yet, I'm still not happy
with the URLs I'm calling to retrieve the data, but that's not a huge deal.
Anyway, on with the show.

First of all, here's your two form elements.

$this-addElement('FilteringSelect', 'fk_client_id', array(
'label'= 'Client:',
'storeId' = 'clientStore',
'storeType'= 'dojo.data.ItemFileReadStore',
'storeParams' = array( 'url' =
'/clients/autocomplete/format/ajax?autocomplete=1str=*',),
'autoComplete'   = 'false',
'hasDownArrow'   = 'true',
'id' = 'fk_client_id',
));

$this-addElement('FilteringSelect', 'fk_client_contact_id', array(
'label'= 'Client contact:',
'storeId' = 'clientContactStore',
'storeType'= 'dojo.data.ItemFileReadStore',
'autoComplete'   = 'false',
'hasDownArrow'   = 'true',
'id' = 'fk_client_contact_id',
));

Now for the javascript, this has to appear somewhere on the page that
contains the form.

dojo.connect(dijit.byId('fk_client_id'), 'onChange', function () {
dijit.byId('fk_client_contact_id').store = new
dojo.data.ItemFileReadStore({ url:
/clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id= +
dijit.byId(fk_client_id).value });
});


As for the URLs for the Datastores, they are kind of an exercise for the
reader, other than to say they obviously should filter correctly on the
passed parameters, and they have to return JSON. This part was pretty
annoying, but I eventually found that a function like this returns the
correct JSON format:

public function prepareAutoCompletion($data) {
$items = array();
foreach ($data as $key = $value) {
$items[] = array('label' = $value, 'name' = $value, 'key' =
$key);
}
$final = array(
'identifier' = 'key',
'items' = $items,
);
return $this-encodeJson($final);
}


You pass in to the function an array of id = value pairs, and it will
output the correct JSON for the FilteringSelects. If you use the built in
AutoCompleteDojo helper, it won't use the id from your table as the value
that the form submits, which is pretty much useless.

Oh, and one more trick, for the Edit action, you are going to need to
include something like this:

$form-populate($row);
$form-getElement('fk_client_contact_id')-setStoreParams(array( 'url' =
'/clientcontacts/autocomplete/format/ajax?autocomplete=1fk_client_id=' .
$form-getElement('fk_client_id')-getValue() ));

So that it prepopulates the form correctly.

I promise I'll write up a really impressive document that spells this whole
thing out in painstaking detail, I'm just absolutely flat out until
christmas, I haven't had any time!


On Tue, Dec 9, 2008 at 10:58 AM, Ace Paul [EMAIL PROTECTED] 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);
 --
 View this message in context:
 http://www.nabble.com/How-to-set-up-dependant-dropdowns-in-form-tp20907379p20907379.html
 Sent from the Zend Framework mailing list archive at Nabble.com.