Sorry this blog is deprecated.
Find latest version of this article here. http://zendgeek.blogspot.com/2009/07/zend-framework-and-dojo-auto-complete.html
Creation of auto complete in Zend Framework using dojo is like a piece of cake. In one of my previous post I discuss how to create filtering select and populate that using dojo and ajax.
Here I am going to discuss how to create auto complete with combo box. The auto complete textbox will automatically/dynamically fetch data from the database.
So lets get started.
First of all create following functions in you controller.
public function getForm()
{
if (null === $this->_form) {
$this->_form = new Zend_Form();
$this->_form->setMethod(‘get’)
->setAction(
$this->getRequest()->getBaseUrl() . ‘/test/process’
)
->addElements(array(
‘test’ => array(‘type’ => ‘text’, ‘options’ => array(
‘filters’ => array(‘StringTrim’),
‘dojoType’ => array(‘dijit.form.ComboBox’),
’store’ => ‘testStore’,
‘autoComplete’ => ‘false’,
‘hasDownArrow’ => ‘true’,
‘label’ => ‘Your input:’,
)),
‘go’ => array(‘type’ => ’submit’,
‘options’ => array(‘label’ => ‘Go!’))
));
}
return $this->_form;
}
In the above code define a function and create a form adding it a combo box.
The important attributes of the combo box are
dojoType, store and autocomplet.