How to Clear Search Widget from a Custom Widget ?

697
3
Jump to solution
02-14-2019 01:33 PM
by Anonymous User
Not applicable

We are working on a Custom Widget.

 

How do I clear the "Search  Widget" (Green)  from a  Custom widget(Red).

Attaching a snap.

 

I tried this code. 

 

var widgets = this.appConfig.getConfigElementsByName('Search');
if (widgets.length > 0) {
debugger;
}
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Muralidhar,

   You will need to get a reference to the search widget from your widget. for that you will need add 'jimu/WidgetManager', to your widgets define array.

Then add this new helper function:

    _getWidgetConfig: function(widgetName){
      var widgetCnfg = null;
      arrayUtils.some(WidgetManager.getInstance().appConfig.widgetPool.widgets, function(aWidget) {
        if(aWidget.name == widgetName) {
          widgetCnfg = aWidget;
          return true;
        }
        return false;
      });
      if(!widgetCnfg){
        /*Check OnScreen widgets if not found in widgetPool*/
        arrayUtils.some(WidgetManager.getInstance().appConfig.widgetOnScreen.widgets, function(aWidget) {
          if(aWidget.name == widgetName) {
            widgetCnfg = aWidget;
            return true;
          }
          return false;
        });
      }
      return widgetCnfg;
    },

And call this code:

      var widgetCfg = this._getWidgetConfig('Search');
      if (widgetCfg) {
        var searchWidget = WidgetManager.getInstance().getWidgetByLabel(widgetCfg.label);
        if(searchWidget){
          searchWidget.searchDijit.set("value", "");
        }
      }

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Muralidhar,

   You will need to get a reference to the search widget from your widget. for that you will need add 'jimu/WidgetManager', to your widgets define array.

Then add this new helper function:

    _getWidgetConfig: function(widgetName){
      var widgetCnfg = null;
      arrayUtils.some(WidgetManager.getInstance().appConfig.widgetPool.widgets, function(aWidget) {
        if(aWidget.name == widgetName) {
          widgetCnfg = aWidget;
          return true;
        }
        return false;
      });
      if(!widgetCnfg){
        /*Check OnScreen widgets if not found in widgetPool*/
        arrayUtils.some(WidgetManager.getInstance().appConfig.widgetOnScreen.widgets, function(aWidget) {
          if(aWidget.name == widgetName) {
            widgetCnfg = aWidget;
            return true;
          }
          return false;
        });
      }
      return widgetCnfg;
    },

And call this code:

      var widgetCfg = this._getWidgetConfig('Search');
      if (widgetCfg) {
        var searchWidget = WidgetManager.getInstance().getWidgetByLabel(widgetCfg.label);
        if(searchWidget){
          searchWidget.searchDijit.set("value", "");
        }
      }
by Anonymous User
Not applicable

Thank you so much. This code worked perfectly.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos