Tuesday, June 15, 2010

Dojo filteringselect popup out of position on window resize

There is an issue(or enhancement request if you want to be specific) with the Dojo dijit.form.FilteringSelect widget where if you resize your browser window while the popup containing the dropdown options is open the popup retains it's original positioning relative to the browser window edge not it's parent widget e.g. the FilteringSelect text box.

This is documented fairly well at Ticket #5777 popups: close when window resized.

In the case of filtering select I feel it is a valid workaround to close the popup on window resize.

My workaround is here, although I am sure there may be more elegant ways. This assumes some familiarity with dojo and the FilteringSelect widget.

Start with the widget itself, assume you have necessary infrastructure for this FilteringSelect i.e. data store, dojo.requires, etc...
<input dojoType="dijit.form.FilteringSelect"
searchAttr="name" store="principalRisk1DataStore" class="medium" id="principalrisk1" name="principalrisk1" />


In order to close the popup containing the drop down selections for this FilteringSelect I need an onResize method


function onWindowResize()
{
//get the popup created when you click the widget, by default this seems to be the id of your input + _popup
var principalRisk1 = dijit.byId('principalrisk1_popup');
//useful for firebug to see what you get
console.debug(principalRisk1);
//this method closes the popup node you retrieved
dijit.popup.close(principalRisk1);
}


Now, lastly add this to the body tag's handler for onresize

<body class="tundra" onresize="onWindowResize()">

No comments:

Post a Comment