onReceiveData from the Search widget is not working.

1120
8
Jump to solution
08-13-2020 01:23 PM
MartinOwens1
Occasional Contributor II

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);
		}
      },
0 Kudos
1 Solution

Accepted Solutions
MartinOwens1
Occasional Contributor II

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');

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Martin,

   the Search widget already has an onReceiveData function... Did you replace that functions contents with what you show above?

0 Kudos
MartinOwens1
Occasional Contributor II

Yeah I just replaced it with what I pasted here. It's not in the code twice.

0 Kudos
CarlosNantes
New Contributor III

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);
},
0 Kudos
MartinOwens1
Occasional Contributor II

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.

0 Kudos
MartinOwens1
Occasional Contributor II

The end goal here is to send a value to the Search dijit and execute the search function.

0 Kudos
MartinOwens1
Occasional Contributor II

Has anyone been able to test this and see if they can receive data in the Search widget?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Martin,

   After testing I can confirm you are correct that the Search widget is Not receiving data. 

0 Kudos
MartinOwens1
Occasional Contributor II

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');