How to save the ID not the text of a Zend_Dojo_Form_Element_ComboBox

Hi all,

I've found how to create a Zend_Dojo_Form_Element_ComboBox to read from a data store and display the results in a autocomplete manner.

I was just wondering if anyone could tell me how to access the associated id of the data displayed in the ComboBox so that I can save the id to the database, as currently the text e.g. Dublin is being saved, not its ID of 10.

Currently my ComboBox code is as follows.
 // Create a autocomplete input for counties
	    $county = new Zend_Dojo_Form_Element_ComboBox('county');
   		$county->setLabel('County');
    	$county->setOptions(array(
          'autocomplete' => true,
          'storeId'   => 'countyStore',
          'storeType' => 'dojo.data.ItemFileReadStore',
          'storeParams' => array('url' => "/clients/client/autocomplete"),
          'dijitParams' => array('searchAttr' => 'county')))
            ->setRequired(true)
            ->addValidator('NotEmpty', true)
            ->addFilter('HTMLEntities')            
            ->addFilter('StringToLower')        
            ->addFilter('StringTrim');

Open in new window


The code for my autocomplete action within the controller is as follows the query returns the ID and County for each county in the table, with the id of the table 'countiesID' being used as the id of the Zend_Dojo_Data element (if I understand what I've read from the web).

public function autocompleteAction()
  {
  	// disable layout and view rendering
	$this->_helper->layout->disableLayout();
	$this->getHelper('viewRenderer')->setNoRender(true);
	
	// get list of breed names from the breeds table
	 $qry= Doctrine_Query::create()
	  	->from('PetManager_Model_Counties c');
	
		$result=$qry->fetchArray();
		
	   //generate and return JSON string 
	   $data = new Zend_Dojo_Data('countiesID',$result,'county');
	   echo $data->toJson();
  }

Open in new window


Many thanks in advance

I.S.
LVL 1
IrishStudentAsked:
Who is Participating?
 
IrishStudentAuthor Commented:
I've actually figured this out mysrelf I should have used FilteringSelect instead of combobox.
0
 
IrishStudentAuthor Commented:
I found the solution myself and no one on here had provided the answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.