Zend Framework and dojo- Auto Complete Example

27 Jan

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.

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

11 Responses to “Zend Framework and dojo- Auto Complete Example”

  1. zendfan January 31, 2009 at 5:39 am #

    Hi.. Could you give us an example using jqGrid with Zend Framework… I really apreciate it… =)

  2. Thang February 1, 2009 at 7:06 am #

    Do we need to revise
    public function records()
    to
    public function recordsAction()
    ?

  3. Faheem Abbas February 1, 2009 at 10:52 am #

    Yeah.
    You are right.

  4. Thang February 2, 2009 at 11:31 pm #

    Hi Faheem Abbas
    I’ve tried it and it work ok. But if I change the selected field to id like this:

    $sql = ‘SELECT id FROM customer’;

    $result = $db->fetchAll($sql);

    $dojoData= new Zend_Dojo_Data(’id’,$result,’id’);

    echo $dojoData->toJson();

    then I catch an exception:
    Item does not have the attribute ‘name’.

    I guess the problem is about the attribute of datastore so I add sortField=”[{attrubute: ‘id’}]” as below:

    <div dojoType="dojox.data.QueryReadStore" jsId="accountStore" sortFields="[{attribute: ‘id’, descending: true}]" url="baseUrl;?>/ledger/records”>

    But the problem is not solved.
    Do you have experience of this error?

  5. Thang February 3, 2009 at 3:36 am #

    Fixed. Just add to form the following line:
    ‘searchAttr’ => ‘id’

    I have another problem:
    When I type into combo box, the full list appear. Type more characters and the list is still full, not reduce to match with the new word typed in the box.

  6. Faheem Abbas February 4, 2009 at 5:18 am #

    Thang,
    To achieve the functionality you are up to, you will need to use another data store.
    Get the value you entered in the combo, send that to your controller/action and create your new data store using javascript. Once you create new data store then assign that data store to the combo.
    Sorry for not having time these days to give you proper tested example. Lot of work this week in office.

  7. Seth February 5, 2009 at 2:16 pm #

    can you show us an example of zend framework with other ajax library like script.aculo.us ? i don’t know why but i don’t like dojo a bit🙂 something simply like save to wishlist, add as friend, star rating, simple stuff like this so we have a base to go from, i realy appreciate it! thanks!🙂

  8. Javi March 10, 2009 at 6:05 am #

    Could you post entire source code please?

    I m having troubles to have a good start zend dojo combo integration to improve a combo dependent.

    I believe your code is newer than those i found, but i couldn’t get it works.

    i believe it could be great!

    Thanks a lot!

  9. Faheem Abbas March 10, 2009 at 7:41 am #

    Sorry,it won’t be possible.
    You can post your problem here.

  10. K March 26, 2009 at 2:51 am #

    Were you able to create a Star Rating control using Zend_Dojo?
    Let us know, how

  11. mic August 26, 2009 at 10:13 pm #

    excelent but i need a example complet or a example without dojo.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: