Has anyone had an issue trying to receive data in the Search widget? I have attempted to publish from multiple other widgets with no luck. Is there something I'm missing on this particular widget?
startup: function() {
this.fetchData();
this.fetchDataByName('Query');
this.inherited(arguments);
onReceiveData: function(name, widgetId, data) {
if (parID.target === "Search") {
parID = data;
console.log('Search ParID data from Query ' + parID.data);
}
},
Solved! Go to Solution.
For anyone that encounters this issue in the future here is how to make the Search widget receive data with the OnReceiveData method:
postCreate: function() {
this.listenWidgetIds.push('Widget ID');
Martin,
the Search widget already has an onReceiveData function... Did you replace that functions contents with what you show above?
Yeah I just replaced it with what I pasted here. It's not in the code twice.
It seems to me that the order that the widgets are been created is causing the problem. Probably Search widget is been created before the other widgets. If this is the case, it seems that this.fetchDataByName('Query') will not find the widget Query because it doesn't exists yet.
Maybe you should try to use dojo/topic module to solve this problem. You'll probably do something like this:
//Search/Widget.js
startup: function() {
this.inherited(arguments);
topic.subscribe('query', lang.hitch(this, this.whenQueryPublishesDo));
//...
},
whenQueryPublishesDo: function(data){
//...process data
console.log(data.result)
},
//Query/Widget.js define([ 'dojo/topic', //.... ]), function( topic,
//... ) //... someMethod: function() { var data = { result : { //... } }; topic.publish('query', data); },
I would think it should still fetch data since I'm calling the fetchData(); method on line 2. The results are published after both widgets are created.
The end goal here is to send a value to the Search dijit and execute the search function.
Has anyone been able to test this and see if they can receive data in the Search widget?
Martin,
After testing I can confirm you are correct that the Search widget is Not receiving data.
For anyone that encounters this issue in the future here is how to make the Search widget receive data with the OnReceiveData method:
postCreate: function() {
this.listenWidgetIds.push('Widget ID');