Defaultiing the focus to the first text field in IE
The Roo-scaffolded views use Dojo decorations for HTML form fields such as text fields, text areas, and select lists. I have a requirement that if any page has a text field on it, the focus should default to that field, so that the user can start typing straight away without having to click into it with their mouse (or use the Tab key).
I've tried adding this script to the end of my default.jspx file, just inside the closing body tag:
Code:
<script type="text/javascript"><![CDATA[
dojo.addOnLoad(
function() {
// Set the focus to the first editable field in the 1st form
var formElements = document.forms[0].elements;
for (var i = 0; i < formElements.length; i++) {
var formElement = formElements[i];
if (formElement.type == 'text') {
formElement.focus();
break;
}
}
}
);
]]></script>
This works fine in Firefox, as follows:

... but not in IE8 (the main target browser for this app), where the first text field gets a different outline to the others, but doesn't accept keyboard input:

If I click in it or tab to it, it works like normal, but that defeats the purpose.
Does anyone know how to properly give the focus to a Dojo-decorated text field?
Andrew Swan
"Now is the EJB of our discontent made glorious Spring"