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.
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<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>widgetName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> widgetCnfg <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> arrayUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">some</SPAN><SPAN class="punctuation token">(</SPAN>WidgetManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getInstance</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>appConfig<SPAN class="punctuation token">.</SPAN>widgetPool<SPAN class="punctuation token">.</SPAN>widgets<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>aWidget<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>aWidget<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> widgetName<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> widgetCnfg <SPAN class="operator token">=</SPAN> aWidget<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>widgetCnfg<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">/*Check OnScreen widgets if not found in widgetPool*/</SPAN> arrayUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">some</SPAN><SPAN class="punctuation token">(</SPAN>WidgetManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getInstance</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>appConfig<SPAN class="punctuation token">.</SPAN>widgetOnScreen<SPAN class="punctuation token">.</SPAN>widgets<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>aWidget<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>aWidget<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> widgetName<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> widgetCnfg <SPAN class="operator token">=</SPAN> aWidget<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> widgetCnfg<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
And call this code:
<SPAN class="keyword token">var</SPAN> widgetCfg <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_getWidgetConfig</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Search'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>widgetCfg<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> searchWidget <SPAN class="operator token">=</SPAN> WidgetManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getInstance</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getWidgetByLabel</SPAN><SPAN class="punctuation token">(</SPAN>widgetCfg<SPAN class="punctuation token">.</SPAN>label<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>searchWidget<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> searchWidget<SPAN class="punctuation token">.</SPAN>searchDijit<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">set</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"value"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thank you so much. This code worked perfectly.
Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.