views:

3536

answers:

4

I'm trying to bind an onChange event of one FilteringSelect to populate another FilteringSelect.

// View
dojo.addOnLoad(function () {
    dojo.connect(dijit.byId('filterselect1'), 'onChange', function () {
        dijit.byId('filterselect2').store = new dojo.data.ItemFileReadStore(
            { url: "/test/autocomplete/id/" + dijit.byId("filterselect1").value }
        );
    });
});

The JSON is generated from what I can tell correctly from a Zend Action Controller using a autoCompleteDojo helper.

// Action Controller
public function autocompleteAction()
{
    $id = $this->getRequest()->getParam('id');
    $select = $this->_table->select()
                           ->from($this->_table, array('id','description'))
                           ->where('id=?',$id);

    $data = new Zend_Dojo_Data('id', $this->_table->fetchAll($select)->toArray(), 'description');

    $this->_helper->autoCompleteDojo($data);
}

I receive the JSON from the remote datastore correctly, but it does not populate the second FilteringSelect. Is there something else I need to do to push the JSON onto the FilteringSelect?

+1  A: 

Try console.log() in the event to see if it is launched. Changing the store should work, however for other widgets like grid you have also to call refreshing methods.

An odd effect; the onChange event does fire, but the call the remote datastore doesn't happen until the filterseletc2 is actvated via some event like onClick or keydown.
Erik
A: 

I couldn't believe this was causing the problem, but the whole issue boiled down to the fact that it appears that a dojo ItemFileReadStore REQUIRES the label property of the JSON to be "name". In the end this is all that it required to wire them together.

dojo.addOnLoad(function () {

    dijit.byId('filtering_select_2').store = new dojo.data.ItemFileReadStore({url: '/site/url'});

    dojo.connect(dijit.byId('filtering_select_1'), 'onChange', function (val) {
        dijit.byId('filtering_select_2').query.property_1 = val || "*";
    });
});

UPDATE: The property within Zend form has been fixed as of ZF 1.8.4

Erik
Actually, all you have to do is set the searchAttr on the control to make it work. You can either add it to the HTML (searchAttr="description") or in the JS (filteringSelect2.searchAttr = "description").
Michael Johnson
You really should make this comment an answer as it really has significant value to the question now, and I'd love to give it an up-vote.
Erik
A: 

Thanks man. I was hooked up with the same problem of populating FilteringSelect dynamically. But I sorted it out after going through this your post. The problem was that data source label property required 'name' as a value while I was using other word as a value.

Thanx once again for sharing.

chibex
A: 

Quick question, where do add my 'dojo.addonload' if am using zend framework MVC and dojo as declarative? And can the 'filteringSelect2.searchAttr' be devclared using zend_dojo_forms? Thanks

dojo.addonload is declared in the view. The search attribute should now be available through using the filtering select control from the Zend_Dojo_Form now. See Michael's comment above.
Erik