Dojo.data undefined Choice of flirting
I'm having trouble with Dojo Filtering Selection while using Zend Framework forms and need help figuring out what I missed as it is driving me crazy.
I am currently getting these errors in firebug :
- dojo.data undefined
- dojo.data.ItemFileReadStore is not a constructor
Below is the code I am using to create a filter and provide json data to the calling controller.
Zend_Form Element (Dojo Enabled)
$industry = new Zend_Dojo_Form_Element_FilteringSelect('industry');
$industry->setAutocomplete(true)
->setStoreId('industrystore')
->setStoreType('dojo.data.ItemFileReadStore')
->setStoreParams(array('url' => $baseUrl.'/dojo/industry'))
->setAttrib("searchAttr", "title")
->setRequired(true)
->removeDecorator('DtDdWrapper')
->removeDecorator('label')
->removeDecorator('HtmlTag');
Dojo Controller
public function industryAction(){
$db = Zend_Db::factory($this->config->database);
$result = $db->fetchAll("SELECT * FROM industries");
$data = new Zend_Dojo_Data('industryid', $result);
$this->_helper->autoCompleteDojo($data);
$db->closeConnection();
}
It's a shame that all of my other Dojo elements in this form and other forms work well, it's just whenever I do Filtering Selects that I hit these problems and this problem causes all other elements in the form to fail.
Thanks in advance.
a source to share
The problem is how the Zend Framework initializes the digits and data stores before the toolkit is fully loaded, in this case specifically the methods that assign the store to the digital. I ran into this issue and found that the best way to work around these issues is to either pass the data store from the controller to a JavaScript variable defined in the view, or do what you did with a specific autocomplete action. Based on your example, I would make the following changes.
In your form, I would simplify the element:
$industry = new Zend_Dojo_Form_Element_FilteringSelect('industry');
$industry->setAutocomplete(true)
->setRequired(true)
->removeDecorator('DtDdWrapper')
->removeDecorator('label')
->removeDecorator('HtmlTag');
In your view, you want to connect the repository to your digital and make sure you load the dojo.data.ItemFileReadStore module:
<?php $this->dojo()->onLoadCaptureStart()?>
function(){
dijit.byId('industry').store = new dojo.data.ItemFileReadStore({ url: '/controller/industry' });
}
<?php
$this->dojo()->onLoadCaptureEnd();
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
?>
As I mentioned, I ran into a similar problem, which I answered here . Another problem I found is that the datastore doesn't like to deal with labels, declaring anything other than "name" to declare the label in Zend_Dojo_Data.
a source to share