On Thu, Sep 20, 2007 at 03:43:45PM -0700, Doug Leeper wrote:
>
> I know this is probably one of the most trivial things to do...but I am
> stumped. No example that I found on the Wicket example site has shown this.
> I know that AjaxRequestTarget#focusComponent plays a part in this but not
> sure how. Could someone post a quick code snippet or place on the Wiki on
> how do to this in 1.3?
>
> Thanks
I include this little script in my base page to always auto-focus the
first text box.
Focus = {};
Focus.setInitialFocus = function() {
// look for inputs with CSS class "invalid" first
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
var input = inputs.item(i);
if (input.className.indexOf("invalid") >= 0) {
input.focus();
input.select();
return;
}
}
for (var i = 0; i < inputs.length; i++) {
var input = inputs.item(i);
if (input.type == "text"
|| input.type == "file"
|| input.type == "password"
|| input.type == "radio"
|| input.type == "checkbox") {
// skip it if it's disabled or has the nofocus CSS class
if (!input.disabled && input.className.indexOf("nofocus") ==
-1) {
input.focus();
return;
}
}
}
}
if (window.addEventListener) {
window.addEventListener("load", Focus.setInitialFocus, true);
} else {
if (window.attachEvent) {
window.attachEvent("onload", Focus.setInitialFocus);
}
}
jk
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]