This alternative InputFocus.script specifies the actual input field
to give the focus to. The target input field is identified by an informal
parameter named component. The script then uses
${expression} element name insertions to complete the JavaScript.
Note when using this script, the target input field component must be declared
before the script component in the HTML template, and within the
Form block, so that the target field component can be
resolved by the Script component.
<body jwcid="body">
<form jwcid="loginForm">
<table cellpadding=
"4">
<tr><td>Username:</td><td><input jwcid="usernameTextField" size=
"12"/></td>
</tr>
<tr><td>Password:</td><td><input jwcid="passwordTextField" size="12"/></td>
</tr>
<tr align="right">
<td colspan="2"><input type="submit" value="Login"/></td>
</tr>
</table>
<span jwcid="inputFocusScript"/>
</form>
</body>
<component id="inputFocusScript" type="Script">
<binding name="component" expression="components.usernameTextField"/>
<static-binding name="script">/com/mycorp/scripts/InputFocus.script</static-binding>
</component>
<!-- Sets the focus to the specified input field if not hidden and not disabled. -->
<!-- /com/mycorp/scripts/InputFocus.script -->
<?xml version="1.0"?>
<!DOCTYPE script PUBLIC
"-//Howard Ship//Tapestry Script 1.1//EN"
"http://tapestry.sf.net/dtd/Script_1_1.dtd">
<!--
Selects the specified form input field on body load if the input type is not
"hidden" and the input field is not disabled.
Input symbols:
component: the component input field to give focus
-->
<script>
<body>
function setFocus() {
var inputField = document.${component.form.name}.${component.name};
if (inputField.type != "hidden") {
if (inputField.disabled != true) {
inputField.focus();
}
} else {
window.alert('InputFocus.script cannot set focus on a hidden field');
}
}
</body>
<initialization>
setFocus();
</initialization>
</script>
|