AnsweredAssumed Answered

Using a value from one widget as a parameter for another

Question asked by jbridwell_Dewberry on Mar 24, 2020
Latest reply on Apr 2, 2020 by jbridwell_Dewberry

I want to use a value from one widget as a parameter to open another widget I currently have a widget, 'InfoTemplate' (a popup) that has a button that launches another widget, `TaskManager`, when clicked:         

var editButton = new Button({     label: "Edit Schedule" }); editButton.on('click', lang.hitch(this, function () {     editButton.setDisabled(true); //disable the edit button on first click     var wm = WidgetManager.getInstance();     var tm = wm.appConfig.widgetPool.widgets[8]; //TaskManager widget     var hc = WidgetManager.getInstance().getWidgetsByName("HeaderController")[0];     hc.setOpenedIds([tm.id]);     editButton.setDisabled(false); }));  editButton.startup();

The task manager widget has two dropdowns, which onOpen, populate with a default list of items from a REST Service
(Project Name, and Subproject Name are the 2 dropdowns/attribute fields that get populated). In the `InfoTemplate` widget,
I am able to get the `Subproject Name` value of the feature being clicked on and create a variable that can be plugged into
my button's `.on('click' function):

      var subproj = updateFeatureOriginal.attributes.projectname;

I have a function in my TaskManager widget that gets the list of subproject names, but more importantly, has an onChange event
handler that loads tasks in a table by subproject:
function createSubprojectDropdown(items) {
// Create subprojects dropdown
     var subprojectNode = dom.byId("subprojectDropdown");
     if (items.length >= 1) {
         var subprojectsOptions = items.map(subproject => {
         return { "label": subproject, "value": subproject }
         });
     }
     else {
         let current_user = parent.thisWidget.getCurrentUser();
         var subprojectsOptions = [{ "label": `No subprojects available to user "${current_user}"`, "value": "NoSubprojects" }]
     }
     // Must check to see if subprojectSelect exists. If it does, destroy that node and create a new one (otherwise you get a registry error)
     var p = registry.byId('subprojectSelect');
     if (p) {
         p.destroyRecursive();
     }
     var subprojectSelector = new Select({
         name: "subprojectSelect",
         id: "subprojectSelect",
         options: subprojectsOptions
     }).placeAt(subprojectNode).startup();

     dijit.byId('subprojectSelect').on('change', function (e) {
         thisWidget.loadData(e, proj_type_obj);
     });
     thisWidget.loadData();
}
  
To do this, I have it calls another function in my TaskManager widget that takes a parameter and populates the table with tasks accordingly (its too long to
paste here):
loadData: function (subproj_name, proj_typ) {....};

The proj_type is determined by the subproj_name and not of concern here. Basically, what I want to do is take the
subproj variable from InfoTemplate (which will be open) and use it to preselect the subproject name from the
dropdown in using my onChange event in the
createSubprojectDropdown function. My initial idea is to simple add
something to check and see if there is a subproject value from InfoTemplate, and if so, send that to the loadData
function
.
var subproj_name = updateFeatureOriginal.attributes.projectname;
if (subproj_name != undefined) {
    thisWidget.loadData(subproj_name, proj_type_obj);
};

Is there an easier way to do this? Should I be using `FeatureAction` or some other methodology?



Outcomes