Zend_Dojo_Form_Element_ComboBox autocomplete not working
Hi all I'm posting this as I can't figure it out. Basically I have a search page in which I have a Zend_Dojo_Form_Element_Combobox. I want to implement autocomplete functionality for this element but its not working. The search functionality works fine I just have to type in text.
I'm thin开发者_如何学JAVAking that my problem is with the setup of the autocompleteAction in my controller, I'll be honest I'm not sure how this is setup. I can't get my head around as I'm new to the Zend Framework, the tutorials I've found online and are of a different format to a book I'm reading on the subject.
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()
->select('b.breed')
->from('PetManager_Model_Breeds b');
$result=$qry->fetchArray();
//generate and return JSON string
$data = new Zend_Dojo_Data('breed',$result);
echo $data->toJson();
}
In case it is my implementation of The element itself here is the code extract from my form class.
// Create a autocomplete inout for breed name
$breedName = new Zend_Dojo_Form_Element_ComboBox('breed');
$breedName->setLabel('Search Breeed Names');
$breedName->setOptions(array(
'autocomplete'=>'false',
'hasDownArrow'=>'true',
'storeID'=>'breedStore',
'storeType'=>'dojox.data.QueryReadStore',
'storeParams'=>array('url'=>"/breeds/breed/autocomplete"),
'dijitParams' =>array('searchAttr' =>'breed')))
->setRequired(true)
->addValidator('NotEmpty',true)
->addFilter('HtmlEntities')
->addFilter('StringToLower')
->addFilter('StringTrim');
Any and all help greatly appreciated.
I.S.
I think you must add a label and specific metadata to your Zend_Dojo_Data object in order to work with the QueryReadStore. Something like this:
//generate and return JSON string
$data = new Zend_Dojo_Data('breed', $result);
$data->setLabel('breed');
$data->setMetadata('numRows', count($result));
echo $data->toJson();
精彩评论