PDA

View Full Version : Focus problems with tab panel content



dougbieber
18 Oct 2010, 7:17 AM
I use java / struts to build my application. When you tell struts (through its form tag) to place initial focus in a field, it automatically generates this X-browser javascvript:
<script type="text/javascript" language="JavaScript">
<!--
var focusControl = document.forms["changeRepresentedDealerForm"].elements["dealerNumber"];
if (focusControl.type != "hidden" && !focusControl.disabled && focusControl.style.display != "none") {
focusControl.focus();
}
// -->
</script>

This has been working fine in my application until my extjs conversion!
My java jsp pages used to simply output themselves as html to the browser and everything worked. With ExtJs, I now use a overall tabbed panel, and the contents of my jsp pages go into a <div></div> which is then referenced as the 'contentEl' for the selected tab.
Needless to say, this also works UNTIL the above code is generated, and attempts to put focus in my required field.
Internet Explorer (version 6, 7 and 8) generates the following error:
"Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."
** My content div is setup with a class of either 'x-hidden' or 'x-hide-display' - to stop flashing when the screen displays
** i.e. <div id="content" class="x-hidden"> or <div id="content" class="x-hide-display">
When I have no class defined for my content <div> I DO NOT get the IE error, however my browser screen flashes the content (a little annoying), AND DOES NOT move focus to the identified text field.
I guess I am registering TWO bugs:
1) Focus shifting throws an IE error with content <div>'s of class 'x-hidden' or 'x-hide-display'
- I am guessing this is because my text fields's parent is hidden, and the above code only checks for itself being hidden
2) Focus shifting doesn't seem to work at all (i.e. focus is not shifted / initialised) when my form, containing my text field to receive focus is in a panel
- No javascript error, just no moving of focus!
Given that struts is still a popular framework, I am sure this must affect other developers?