How to use a method declared in a webApp builder widget's main js?

180
2
Jump to solution
05-14-2020 02:11 AM
DávidGregor
New Contributor II

I have programing theory question. I need to develop the editor widget, to fill out input boxes automatically with webmapID, date, ect. I'm trying to follow the widget's techniques, but i'm unsuccesfull.

So here i want to get the webmapid in widget.js, but probably it's already not good, because i don't have 'map' in that scope. In the widget.js's startup function i call this method "this.getWebMapId(); And it returns the value.

My big problem,(except that i'm really new in programming) is how to call this method in the RelatedRecordsEditor.js's "_init" function.  Should i declare it like the Clazz object's property? What should i do with the _editWidget object in RelatedRecordsEditor?

What i have done:

widget.js:

      /*******************************
       * Public methods
       * *****************************/

      getWebMapId: function() {
        var webMapID = this.map.itemInfo.item.id;
        console.log("webmapid: "webMapID);
        return webMapID;     
      },

RelatedRecordsEditor.js:

      dojo.connect(dijit.byId('dijit_form_ValidationTextBox_1'), 'onChange'function (webMapID) {
        var mapid=dijit.byId("dijit_form_ValidationTextBox_1").attr("value");
        console.log(mapid);
        var webMapID;
        webMapID = this._editWidget.getWebMapId();  
        var update = mapid.replace(mapidwebMapID);
        console.log(update);
        dojo.byId('dijit_form_ValidationTextBox_1').value = update;
      });

(_editWidget is undefined here.)

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Dávid,

   You need to get a reference to the edit widget in the RelatedRecordsEditor.js file. The normal way to do this is to use the WidgetManager.js class to get the widget reference.

require(["jimu/WidgetManager"], function(WidgetManager) {
  var _editWidget = WidgetManager.getInstance().getWidgetsByName('Edit');
  var webMapID = _editWidget[0].getWebMapId();
});‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Dávid,

   You need to get a reference to the edit widget in the RelatedRecordsEditor.js file. The normal way to do this is to use the WidgetManager.js class to get the widget reference.

require(["jimu/WidgetManager"], function(WidgetManager) {
  var _editWidget = WidgetManager.getInstance().getWidgetsByName('Edit');
  var webMapID = _editWidget[0].getWebMapId();
});‍‍‍‍
DávidGregor
New Contributor II

I was trying to understand the file's communication rather. And some minutes ago a solved it like this, but i will use your answer in the future for sure.

    
 _init: function() {
  
      var webMapIDthis._editWidget.map.itemInfo.item.id;
      
      dojo.connect(dijit.byId('dijit_form_ValidationTextBox_3'), 'onChange'function () {
        var mapid=dijit.byId("dijit_form_ValidationTextBox_1").attr("value");
        console.log("itemid:"+webMapID)
        console.log(mapid);       
        var update = mapid.replace(mapid, webMapID);
        console.log(update);
        dojo.byId('dijit_form_ValidationTextBox_1').value = update;
      });
},

Unfortunately, i realised that it fills the inputbox, but if the user doesn't modify the string, it doesn't save the string what is inside the dijit_form_ValidationTextBox_1   so i need to figure out how to pass this value to the system.

But a thousand thanks for your help!

0 Kudos